1.1.0 • Published 6 months ago

ndume v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Ndume

Ndume is a JavaScript class designed to simplify API calls using the fetch method. It provides a convenient way to make HTTP requests with support for various HTTP methods, request headers, and request body formats.

Installation

Install the Ndume package using npm:

npm install ndume

## Usage
const Ndume = require('ndume');

// Create an instance of Ndume with the base API route
const api = new Ndume('https://api.example.com');

// Set an authorization token if required
api.setToken({
  type: 'Bearer',
  token: 'your_access_token',
});

// Make a GET request
api.GET('/endpoint')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

API

new Ndume(baseRoute: string) Creates a new instance of Ndume with the specified base route.

setToken(token: { type: string, token: string }) Sets the authorization token for the requests.

BaseRequest(method: string, bodyType: string, body: any, path: string, params: Object): Promise Performs a basic request using the fetch method. Returns a Promise containing the fetch request response.

BodyTreatMent(body: any, bodyType: string): Promise Formats the request body to the proper format. Returns a Promise containing the formatted request body.

ParamThreatMent(params: Object): string Formats request parameters to a query string. Returns the formatted parameter string.

POST(body: any, bodyType: string, path: string, params: Object): Promise Performs a POST request. Returns a Promise containing the POST request response.

PUT(body: any, bodyType: string, path: string, params: Object): Promise Performs a PUT request. Returns a Promise containing the PUT request response.

GET(path: string, params: Object): Promise Performs a GET request. Returns a Promise containing the GET request response.

DELETE(path: string, params: Object): Promise Performs a DELETE request. Returns a Promise containing the DELETE request response.

PATCH(body: any, bodyType: string, path: string, params: Object): Promise Performs a PATCH request. Returns a Promise containing the PATCH request response.

License

Contribuições

Fique à vontade para contribuir para este projeto. Veja o arquivo CONTRIBUTING.md para obter detalhes.

1.1.0

6 months ago

1.0.0

6 months ago