Skip to main content

setHeaders()

Description

Sets custom headers that are added to every request of the RestDataProvider

info

The headers passed to setHeaders() are merged into the default Content-Type: application/json header and sent with each request. This is commonly used to pass an authorization token (for example, the Remote-Token header) in a multiuser backend.

Usage

setHeaders(headers: object): void;

Parameters

NameTypeDescription
headersobjectRequired. An object with custom headers added to every request

Example

const { RestDataProvider } = todo;

const url = "https://some_backend_url";

login(url).then(token => {
const restProvider = new RestDataProvider(url);
restProvider.setHeaders({
"Remote-Token": token,
});
// ... initialize the To Do List and connect the provider
});

Related articles: Working with Server