Advanced Request Configuration
Whenever you make a petition, the SDK makes HTTP requests with default headers in the background. These headers are useful in almost every scenario, however, you may also want to send custom headers as a part of your request. To do this, Carbon offers personalized requests. You can view a full list of Carbon’s methods and how to use personalized requests in the API Reference.
Example
You may have to send the authorization header because of how your architecture is setup, to do this, you just have to pass a custom object to the method you’re using, in this case, the $getMembers()
method.
// Set custom headers using the Header Class.
let customHeaders:Map<string, Header> = new Map();
customHeaders.set("Authorization", new Header(TOKEN))
// Options Object
let customOptions:GETOptions = {
ensureLatest: true, // Ignore cache and make request
timeout: 3000, // Time in milliseconds
headers: customHeaders // Custom Headers
};
let queryResults = await this.carbon.documents.$getMembers("authors/", customOptions, _ => _
.properties(_.all)
.properties({contactInfo: {
query: _ => _
.properties(_.all)
}})
)