Skip to content

Abdallah-Zidan/http-task

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

http-task

Modern, promise & task based http client for nodejs

Table of Contents

Features

  • Send http requests as promises or tasks
  • Conversion from tasks back to promise
  • Useful operators for response transformation
  • Parsing json responses
  • informative error message.
  • [New] task based requests for advanced control [task mapping, chaining , concurrency]
  • It uses axios so it supports all what axios supports

Installing

  • Not there yet but will be as following

Using npm:

$ npm install http-task

Using yarn:

$ yarn add http-task

Examples

// promise based
const { request, sendRequest, Types, Request } = require("http-task");

// this approach allows for configuring and sending the request later
let r = request({
  url: "https://jsonplaceholder.typicode.com/todos/1",
  enableDefaultInterceptors: true,
});

r.allowUnauthorized()
  .setContentType(Types.XML)
  .send()
  .then(console.log)
  .catch(console.log);

// or alternatively

sendRequest({
  url: "https://jsonplaceholder.typicode.com/todos/1",
  enableDefaultInterceptors: true,
  allowUnauthorized: true,
  headers: {
    "Content-Type": Types.XML,
  },
})
  .then(console.log)
  .catch(console.log);

// fork a new request from previous one's configurations
Request.from(r)
  .addConfig({
    url: "<different url>",
  })
  .send()
  .then(console.log)
  .catch(console.log);

Todo

- more examples coming

Credits

- Abd Allah Zidan

License

- MIT

About

Task based http client for node js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published