doquery
v1.0.8
Published
This library simplifies HTTP requests in any Node.js project. Say goodbye to try-catch complications, and easily handle multiple HTTP requests also.
Downloads
5
Maintainers
Readme
Do Query library
This library simplifies HTTP requests in any Node.js project. Say goodbye to try-catch complications, and easily handle multiple HTTP requests also.
Installation
Install doQuery library in any node js project
npm i doquery
yarn add doquery
How to use it
if you want to do single query, use useQuery method
import { doQuery } from "doquery";
const requestHeader = {
"Content-Type" : "application/json"
}
const requestBody = {
gmail : "[email protected]",
password : "userpassword"
}
const handleSingleRequest = async () => {
const { success, response, error } = await doQuery({
url : "https://demo.com/login",
method : "POST", // optional. default is GET
header : requestHeader, //optional
body : requestBody, //optional,
cache : "default" //optional
});
if(!success){
setError(error?.message)
return;
}
setResponse(response);
}
if you want to do multiple queries, use doQueries method
import { doQueries } from "doquery";
const requestHeader1 = {
"Content-Type" : "application/json"
}
const requestBody1 = {
gmail : "[email protected]",
password : "userpassword"
}
const handleMultipleRequests = async () => {
const url1 = "https://demo.com/login";
const url2 = "https://demo.com/getsecuritykey";
const { successes, responses, errors } = await doQueries({
urls : [ url1, url2 ],
methods : [ "POST", "GET" ], // optional
headers : [ requestHeader1 ], //optional
bodies : [ requestBody1 ], //optional,
caches : [ "default", "force-cache" ] //optional
});
// if(errors.length != 0){
// errorList(errors)
// return;
// }
const isAnyError = successes.includes(false);
if(isAnyError){
errorList(errors);
return;
}
responseList(responses)
}
Contributing
See the contribution guidelines before creating a pull request.