Passing Custom Headers

Passing Custom Headers

Sometimes when making CRUD operations you may need to pass custom headers to the Telerik Platform services. For example you may want to send data as a header value and consume it you Cloud Code.

The Backend Services JavaScript SDK allows passing custom headers through the withHeaders() function. It accept a plain object with its properties used for header names and values as in the following example.

{
    'custom-header-foo': 'foo',
    'custom-header-bar': 'bar'
}

Headers passed this way are used in the subsequent request and cleared immediately after that. The next example sets headers for the execution of the get() method.

var el = new Everlive('your-app-id');
var data = el.data('type-name');
data
    .withHeaders({'X-Custom-Header': 'custom header value'})
    .get() // a request is made with the custom header
    .then(function(data) {
        var item = data.result[0];
        item['Author'] = 'changed'; // returning a new promise
        return data.updateSingle(item); // this request will not send the custom header
    })
    .then(function(data) {
        alert(JSON.stringify(data));
    },
    function(error) {
        alert(JSON.stringify(error));
    });

See Also

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.