Skip to content

japple-jnode/request

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@jnode/request

Simple HTTP(S) requesting package for Node.js.

Installation

npm i @jnode/request@beta

Quick start

Import

const { request, FormPart } = require('@jnode/request');

Make a request

request('GET', 'https://example.com/').then((res) => {
  console.log(res.text());
});

Make a multipart/form-body request

request('POST', 'https://example.com/', [
  new FormPart('foo', 'bar'),
  new FormPart('awa', 'uwu')
]).then((res) => {
  console.log(res.text());
});

Reference

request.request(method, url[, body, headers, options])

Make a HTTP(S) request.

Class: request.FormPart

new request.FormPart(name, body[, headers, options])

Class: request.RequestResponse

new request.RequestResponse(res)

requestResponse.res

requestResponse.statusCode

The response HTTP status code.

requestResponse.headers

The response HTTP headers.

requestResponse._body

Notice: You should avoid reading this property directly, use requestRespond.buffer() instead.

requestResponse.buffer()

Receives the body of the response stream and return as a buffer.

requestResponse.text([encoding])

  • encoding <string> The character encoding to use. Default: 'utf8'.
  • Returns: <Promise> Fulfills with a string.

Receives the body of the response stream and return as a string.

requestResponse.json([encoding])

Receives the body of the response stream and parse string as JSON.

requestResponse.rl()

Provides an interface for reading data from response one line at a time.

requestResponse.sse()

Provides an interface for reading data from response as Server-Sent Events (SSE, text/event-stream).

Class: request.EventReceiver

An interface for reading data from <stream.Readable> as Server-Sent Events (SSE, text/event-stream).

new request.EventReceiver(res)

Event: 'close'

Emitted when the request has been completed.

Event: 'event'

eventReceiver.res

The response stream or any readable stream.

eventReceiver.rl

An interface for reading data from response one line at a time.

eventReceiver[Symbol.asyncIterator]()

Create an AsyncIterator object that iterates through each event as an object. This method allows asynchronous iteration of InterfaceConstructor objects through for await...of loops.

for await (const event of eventReceiver) {
    // Each event in the event stream will be successively available here as
    // { data, event, id }
}

About

Simple HTTP(s) package for Node.js.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors