@popovmp/client-request
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Client-request

A simple client request library for node.js.

It parses the body according to the content type.

GET request

async function requestGet(url, headers)

const url     = "https://httpbin.org/get?foo=bar";
const headers = {"Accept": "application/json"};

const res = await requestGet(url, headers);

POST request

async function requestPost(url, data, headers)

const url     = "https://httpbin.org/post?foo=bar";
const body    = "Hello, World!";
const headers = {"Content-Type": "text/plain"};

const res  = await requestPost(url, body, headers);

PUT Request

async function requestPut(url, data, headers)

Same as POST request.

POST Json request

async function requestJson(url, data, headers)

const url     = "https://httpbin.org/post?foo=bar";
const json    = {number: 42, text: "foo", list: [1, 2], object: {bar: "baz"}};
const headers = {Client: "request-service"};

const res  = await requestJson(url, json, headers);

POST form URL encoded request

async function requestForm(url, formData, headers)

const url     = "https://httpbin.org/post?foo=bar";
const form    = {number: 42, text: "foo", list: [1, 2]};
const headers = {Client: "request-service"};

const res  = await requestForm(url, form, headers);

Readme

Keywords

none

Package Sidebar

Install

npm i @popovmp/client-request

Weekly Downloads

150

Version

1.0.2

License

MIT

Unpacked Size

17.2 kB

Total Files

7

Last publish

Collaborators

  • popovmp