Skip to content

The fetch-request-browser package makes working with external APIs simple and efficient. This intuitive wrapper leverages the power of the Fetch API, providing a clean and concise interface for your API interactions.

License

Notifications You must be signed in to change notification settings

jesusgraterol/fetch-request-browser

Repository files navigation

Fetch Request Browser

The fetch-request-browser package makes working with external APIs simple and efficient. This intuitive wrapper leverages the power of the Fetch API, providing a clean and concise interface for your API interactions.

If you are working on a node-based environment, make use of fetch-request-node instead.


Getting Started

Install the package:

$ npm install -S fetch-request-browser

Usage

import { send } from 'fetch-request-browser';

await send(
  'https://httpbin.org/get', 
  { 
    requestOptions: {  
      method: 'GET' 
    } 
  }, 
  [3, 5, 10]
);
// {
//   code: 200,
//   headers: Headers {
//     date: 'Tue, 04 Jun 2024 18:52:29 GMT',
//     'content-type': 'application/json',
//     'content-length': '407',
//     connection: 'keep-alive',
//     server: 'gunicorn/19.9.0',
//     'access-control-allow-origin': '*',
//     'access-control-allow-credentials': 'true'
//   },
//   data: {
//     args: {},
//     headers: {
//       Accept: 'application/json',
//       'Accept-Encoding': 'br, gzip, deflate',
//       'Accept-Language': '*',
//       'Content-Type': 'application/json',
//       Host: 'httpbin.org',
//       'Sec-Fetch-Mode': 'cors',
//       'User-Agent': 'node',
//       'X-Amzn-Trace-Id': '...'
//     },
//     origin: '...',
//     url: 'https://httpbin.org/get'
//   }
// }

API

Build and send an HTTP Request (any method):

send(
  input: IRequestInput, 
  options?: Partial<IOptions>,
  retryDelaySchedule?: number[],
): Promise<IRequestResponse>

Build and send a GET HTTP Request:

sendGET(
  input: IRequestInput,
  options?: Partial<IOptions>,
  retryDelaySchedule?: number[],
): Promise<IRequestResponse>

Build and send a POST HTTP Request:

sendPOST(
  input: IRequestInput,
  options?: Partial<IOptions>,
  retryDelaySchedule?: number[],
): Promise<IRequestResponse>

Build and send a PUT HTTP Request:

sendPUT(
  input: IRequestInput,
  options?: Partial<IOptions>,
  retryDelaySchedule?: number[],
): Promise<IRequestResponse>

Build and send a PATCH HTTP Request:

sendPATCH(
  input: IRequestInput,
  options?: Partial<IOptions>,
  retryDelaySchedule?: number[],
): Promise<IRequestResponse>

Build and send a DELETE HTTP Request:

sendDELETE(
  input: IRequestInput,
  options?: Partial<IOptions>,
  retryDelaySchedule?: number[],
): Promise<IRequestResponse>

Built With

  • TypeScript

Running the Tests

# Unit Tests
$ npm run test:unit

# Integration Tests
$ npm run test:integration

License

MIT


Acknowledgments


@TODOS

  • Improve the docs

Deployment

Install dependencies:

$ npm install

Build the library:

$ npm start

Publish to npm:

$ npm publish

About

The fetch-request-browser package makes working with external APIs simple and efficient. This intuitive wrapper leverages the power of the Fetch API, providing a clean and concise interface for your API interactions.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published