Skip to content

This library simplifies HTTP requests in any Node.js project. Say goodbye to try-catch complications, and easily handle multiple HTTP requests also.

Notifications You must be signed in to change notification settings

guptasomnath/doQuery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 : "usergmail@gmail.com",
  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 : "usergmail@gmail.com",
  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.

About

This library simplifies HTTP requests in any Node.js project. Say goodbye to try-catch complications, and easily handle multiple HTTP requests also.

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published