Web APIs
GitBook's Runtime API allows you to use a few Web APIs directly out of the box.
fetch()
fetch()Integrations communicate with the outside world over HTTP. Your integration can send async HTTP requests through HTTP Fetch. See the MDN docs to learn more.
Example:
const resp = await fetch(
`https://example.com/api/endpoint`,
{
headers: {
Authorization: `<example-auth>`,
Accept: 'application/json',
},
}
);Response
ResponseThe Response interface of the Fetch API represents the response to a request. See the MDN docs to learn more.
Example:
const handleFetchEvent = async (request, context) => {
return new Response({message: "Hello World"});
};Request
RequestThe Request interface of the Fetch API represents a resource request. See the MDN docs to learn more.
Example:
const request = new Request("https://example.com", {
method: "POST",
body: '{"message": "Hello World"}',
});
URL
URLThe URL() constructor returns a newly created URL object representing the URL defined by the parameters. See the MDN docs to learn more.
Example:
// Base URLs:
let baseUrl = "https://gitbook.com/";
let integrations = new URL("/integrations", baseUrl);
// => 'https://gitbook.com/integrations'URLSearchParams
URLSearchParamsThe URLSearchParams interface defines utility methods to work with the query string of a URL. See the MDN docs to learn more.
Was this helpful?