Skip to content

Repository files navigation

raw-http

Send HTTP request and get response.

Features

  • Send HTTP request and get response
  • Send multiple requests sequentially in the same file (separated by ### delimiter)
  • Comments support (line starts with #)

Install

npm install @codeit-com/raw-http

Usage

Follow the standard RFC2616 that including request method, uri, headers, and body.

const{ RawHttpClient }=require("@codeit-com/raw-http")consthttpRequest=`POST https://jsonplaceholder.typicode.com/posts HTTP/1.1Content-type: application/json; charset=UTF-8{ title: 'foo', body: 'bar', userId: 1,}`constclient=newRawHttpClient({beautify: true})client.requestAll(httpRequest).then(responses=>{console.log(responses[0])})// HTTP/1.1 201 Created// Date: Wed, 09 Jun 2021 01:22:56 GMT// ...// // {// id: 101,// title: 'foo',// body: 'bar',// userId: 1// }

API

new RawHttpClient(options?: RawHttpClient.Options)

Create a RawHttpClient instance.

Options

{beautify: boolean// Beautify response body if it's JSON. Default is false.}

.requestAll(rawRequestsText: string): string[]

Execute all requests in rawRequestsText and return raw responses.

License

MIT

About

Send HTTP request and get response

Topics

Resources

Stars

1 star

Watchers

2 watching

Forks

Used by

Contributors

Languages