native-api-service
A simple way to make API request from the client end
Installation
Use the package manager npm to install native-api-service.
npm install native-api-service
Explanation
ApiService.request(method, path, callback, errorCallback, payload, exectuteWhileLoading);
- method: this is any of the HTTP request method - get, delete, head, options, posst, put, patch,
- path: this is the relative path to the needed resource - '/user'
- callback: this is a function that gets executed when the request is successful - (response) => console.log('response from API -> ', response)
- errorCallback: this is a error function that gets executed when the request fails - (error) => console.log('error from API -> ', error)
- payload (optional): this is an object that needs you to send data to the API - { key: value }
- exectuteWhileLoading (optional): this is a function that gets executed while the request is loading - NB: you can show a toast or upload progress
Usage
; const userApiService = 'https://jsonplaceholder.typicode.com';// or// const userApiService = new ApiService('https://jsonplaceholder.typicode.com', 'Bearer **token**');// or// const userApiService = new ApiService('https://jsonplaceholder.typicode.com', 'Bearer **token**', 'application/json');userApiService;
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.