@haensl/http
Simple JSON support module bundling common HTTP headers, status codes and methods.
Installation
Via npm
$ npm install -S @haensl/http
Via yarn
$ yarn add @haensl/http
Usage
-
Install @haensl/http
-
Use http status codes, methods and headers in your projects:
ESM, i.e. import
import { statusCodes} from '@haensl/http';
const response = await fetch(url);
if (response.statusCode < statusCodes.badRequest) {
}
CJS, i.e. require
const { headers, methods } = require('@haensl/http');
const requestOptions = {
headers: {
[headers.contentType]: 'application/json'
},
method: methods.post,
body: JSON.stringify(data)
};
const response = await fetch(url, requestOptions);
Synopsis
The http
object is a simple JSON object that maps status codes, headers and strings:
{
"statusCodes": {
"ok": 200,
"created": 201,
"accepted": 202,
},
"headers": {
"accept": "Accept",
"accessControl": {
"allow": {
"origin": "Access-Control-Allow-Origin",
"methods": "Access-Control-Allow-Methods"
},
},
"authorization": "Authorization",
"contentType": "Content-Type",
},
"methods": {
"delete": "delete",
"get": "get",
}
}
Attention: This JSON object is not exhaustive(, yet)! If you need a status code, header or method added, please create a feature request