@codeit-com/raw-http
TypeScript icon, indicating that this package has built-in type declarations

0.2.4 • Public • Published

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")

const httpRequest = `
POST https://jsonplaceholder.typicode.com/posts HTTP/1.1
Content-type: application/json; charset=UTF-8

{
  title: 'foo',
  body: 'bar',
  userId: 1,
}
`
const client = new RawHttpClient({ 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

Readme

Keywords

Package Sidebar

Install

npm i @codeit-com/raw-http

Weekly Downloads

1

Version

0.2.4

License

MIT

Unpacked Size

18.3 kB

Total Files

23

Last publish

Collaborators

  • scon.io
  • pueue