logo

Fetch

The Fetch class is an isomorphic utility built on top of the native Fetch API, meaning it can be used in both Node.js and browsers.

  • The body and headers of the request are automatically generated based on the body.
  • The body of the response is dynamically parsed based on the Content-Type header, unless the parse option is set to false.
  • Enabling logs will give you a detailed overview of the requests and responses.

Send a request

The send, connect, delete, get, head, options, patch, post, put and trace methods can be used to send a request.

import { Fetch } from '@aracna/core';

(async () => {
  let response;

  response = await Fetch.send('https://dummyjson.com/users');
  if (response instanceof Error) return;

  // will log FetchResponse
  console.log(response.data);
})();