hermes-http
Another wrap over fetch
Features
- Make http requests for browser and node (using node-fetch)
- Avoid duplicate requests
- Intercept request, success response and error response
- Abort requests
- Retry requests
- Automatic conversion of request/response data
- Typescript out of the box
Install
Using npm
npm i hermes-http
Using npm
yarn add hermes-http
Using pnpm
pnpm add hermes-http
Using hermes
Hermes work with instances of http clients
const hermes = ;
Now you can use hermes instance to perform http requests.
- Get with query parameters
The second arg of hermes.get
accept a query key for convert
an object in query string and concat with URL.
URL = "https://swapi.co/api/people" query = { search: "r2" } URL + query = "https://swapi.co/api/people?search=r2"
// old school stylehermes.get"https://swapi.co/api/people", .thenconsole.inforesponse .catch;// async/awaittry catch e
For post request, you just drop the object as second parameter and hermes will make all job for you.
/* Hermes apply JSON.stringify on this object to perform request*/;
Http Methods
;
- hermes.get(url, RequestParams)
- hermes.delete(url, RequestParams)
- hermes.post(url, body, RequestParams)
- hermes.put(url, body, RequestParams)
- hermes.patch(url, body, RequestParams)