@bravejs/http-request

BraveJS Http Request Component

Usage no npm install needed!

<script type="module">
  import bravejsHttpRequest from 'https://cdn.skypack.dev/@bravejs/http-request';
</script>

README

BraveJS Http Request

This package will help you to define an object-oriented layer for the HTTP specification.

Installation

npm i @bravejs/http-request

Usage

The most common way to create an instance from IncommingMessage informations

const request = Request.createFromGlobals()

Query Strings

You can easly handle query strings of the current request. for example let's setting a query string

request.query.set('foo', 'bar')

Let's remove it

request.query.remove('foo')

Let's check if it exists

request.query.has('foo')

Headers, and Cookies

You can deal with request headers as the same as dealing with query strings

For headers it's.

request.headers

For cookies it's

request.cookies

Methods

You can get the current method.

request.getMethod()

Or even check its value.

request.isMethod('GET')

Another Methods

Determine whether the request secured or not.

request.isSecure()

Get subdomains of the current request.

request.subdomains()

Determine whether the request is a XMLHttpRequest (Ajax).

request.isXmlHttpRequest()

Gets a list of charsets acceptable by the client browser.

request.charsets()

Gets a list of encodings acceptable by the client browser.

request.getEncodings()

Gets a list of content types acceptable by the client browser.

request.getAcceptableContentTypes()