Static
getStatic
postPosts array buffer data to a URL
Posts array buffer data to a URL with a POST request.
The parameters for the POST request
The parsed response
HTTPError if the response is not ok
ZodError if the response is not valid
const data = await Fetcher.postArrayBuffer({
urlBuilder: new URLBuilder({ baseUrl: 'https://api.example.com' }),
body: new ArrayBuffer(),
schema: z.object({ name: z.string() }),
contentType: 'application/octet-stream',
Static
postPosts blob data to a URL
Posts blob data to a URL with a POST request.
The parameters for the POST request
The parsed response
Static
postPosts form data to a URL
Posts form data to a URL with a POST request.
The parameters for the POST request
The parsed response
HTTPError if the response is not ok
ZodError if the response is not valid
const data = await Fetcher.postFormData({
urlBuilder: new URLBuilder({ baseUrl: 'https://api.example.com' }),
body: new FormData(),
schema: z.object({ name: z.string() }),
contentType: 'application/x-www-form-urlencoded',
Static
postPosts JSON data to a URL
Posts JSON data to a URL with a POST request.
The parameters for the POST request
The parsed response
HTTPError if the response is not ok
ZodError if the response is not valid
const data = await Fetcher.postJson({
urlBuilder: new URLBuilder({ baseUrl: 'https://api.example.com' }),
body: { name: 'example' },
schema: z.object({ name: z.string() }),
contentType: 'application/json',
});
Static
postPOST text data to a URL
Posts text data to a URL with a POST request.
The parameters for the POST request
The parsed response
Fetcher class for fetching data from a URL
This class provides methods for fetching data from a URL with different content types. It uses the URLBuilder class to build the URL and the Zod schema to parse the response. It also uses the fetch API to make the request.
Example