npm module with APIs for cleaner request and basic http requests utils. Contains constants for protocols, http headers, methods, and content types
Find the demos in the demos folder
Using request
function using request-apis package
const reqApis = require("request-apis");
reqApis.request("https://www.google.com").then(r => r.text()).then(r => console.log(r));
Using _fetch
function using request-apis package
const reqApis = require("request-apis");
reqApis._fetch("https://www.google.com", "text").then(r => console.log(r));
Create a general any
method request. Allows for handling connect, error, upgrade events specifically. Simple implementation and allows for request and response interceptor functions.
Usage:
.request(options, data, protocol, connectHandler, contentHandler, errorHandler, upgradeHandler)
/**
*
*
* @param {*} options
* @param {*} data
* @param {*} protocol
* @param {*} connectHandler
* @param {*} contentHandler
* @param {*} errorHandler
* @param {*} upgradeHandler
* @return {*} Promise: resolve<{ headers, body }>, reject <{ error }>
*
*/
Create a get request. Allows for handling connect, error, upgrade events specifically. Simple implementation and allows for request and response interceptor functions.
Usage:
.getRequest(options, data, protocol, connectHandler, contentHandler, errorHandler, upgradeHandler)
.getRequest(options)
.get(options)
/**
*
*
* @param {*} options
* @param {*} data
* @param {*} protocol
* @param {*} connectHandler
* @param {*} contentHandler
* @param {*} errorHandler
* @param {*} upgradeHandler
* @return {*} Promise: resolve<{ headers, body }>, reject <{ error }>
*
*/
Create a post request. Allows for handling connect, error, upgrade events specifically. Simple implementation and allows for request and response interceptor functions.
Usage:
.postRequest(options, data, protocol, connectHandler, contentHandler, errorHandler, upgradeHandler)
.postRequest(options, data, protocol)
.post(options, data, protocol)
/**
*
*
* @param {*} options
* @param {*} data
* @param {*} protocol
* @param {*} connectHandler
* @param {*} contentHandler
* @param {*} errorHandler
* @param {*} upgradeHandler
* @return {*} Promise: resolve<{ headers, body }>, reject <{ error }>
*
*/
Create a put request. Allows for handling connect, error, upgrade events specifically. Simple implementation and allows for request and response interceptor functions.
Usage:
.putRequest(options, data, protocol, connectHandler, contentHandler, errorHandler, upgradeHandler)
.putRequest(options, data, protocol)
.put(options, data, protocol)
/**
*
* @param {*} options
* @param {*} data
* @param {*} protocol
* @param {*} connectHandler
* @param {*} contentHandler
* @param {*} errorHandler
* @param {*} upgradeHandler
* @return {*} Promise: resolve<{ headers, body }>, reject <{ error }>
*
*/
Create a patch request. Allows for handling connect, error, upgrade events specifically. Simple implementation and allows for request and response interceptor functions.
.patchRequest(options, data, protocol, connectHandler, contentHandler, errorHandler, upgradeHandler)
.patchRequest(options, data, protocol)
.patch(options, data, protocol)
/**
*
*
* @param {*} options
* @param {*} data
* @param {*} protocol
* @param {*} connectHandler
* @param {*} contentHandler
* @param {*} errorHandler
* @param {*} upgradeHandler
* @return {*} Promise: resolve<{ headers, body }>, reject <{ error }>
*
*/
Create a delete request. Allows for handling connect, error, upgrade events specifically. Simple implementation and allows for request and response interceptor functions.
Usage:
.deleteRequest(options, data, protocol, connectHandler, contentHandler, errorHandler, upgradeHandler)
.deleteRequest(options)
.del(options)
/**
*
* @param {*} options
* @param {*} data
* @param {*} protocol
* @param {*} connectHandler
* @param {*} contentHandler
* @param {*} errorHandler
* @param {*} upgradeHandler
* @return {*} Promise: resolve<{ headers, body }>, reject <{ error }>
*
*/
Create a options request. Allows for handling connect, error, upgrade events specifically. Simple implementation and allows for request and response interceptor functions.
Usage:
.optionsRequest(options, data, protocol, connectHandler, contentHandler, errorHandler, upgradeHandler)
.optionsRequest(options)
.options(options)
/**
*
*
* @param {*} options
* @param {*} data
* @param {*} protocol
* @param {*} connectHandler
* @param {*} contentHandler
* @param {*} errorHandler
* @param {*} upgradeHandler
* @return {*} Promise: resolve<{ headers, body }>, reject <{ error }>
*
*/
Response content handler function handling content-type of different types. Currently has application/json, application/xml handlers. Parses the 'content-type': 'application/json'
like headers from res.headers
.contentTypeHandler(responseObject, responseBody)
/**
* Different contentTypeHandler Handlers
*
* @param {*} responseObject
* @param {*} responseBody
* @return { headers, body }
*/
Check and get type of protocol - http or https
.checkHttpsProtocol(url)
/**
*
* @param {*} url
* @return {*} Boolean
*
*/
Check and Get the protocol of the url.
.getProtocol(url)
/**
*
* @param {*} url
* @return {*} Boolean
*
*/
Is the url a valid url structure.
.isValidURL(url)
/**
*
* @param {*} url
* @return {*} Boolean
*
*/
Different HTTP Constants associated to the package provided as an JS Object. Can be useful for testing/ automated testing purposes, etc.
List of Different HTTP Request headers for HTTP
require("request-apis").constants.REQUEST_HEADERS
List of Different HTTP Request headers categorized for HTTP
require("request-apis").constants.REQUEST_HEADERS_CATEGORIZED
List of Different HTTP Response headers for HTTP
require("request-apis").constants.RESPONSE_HEADERS
List of Different HTTP Response headers categorized for HTTP
require("request-apis").constants.RESPONSE_HEADERS_CATEGORIZED
List of Different HTTP Protocols for Node.js - http
, https
require("request-apis").constants.PROTOCOLS
List of Different HTTP Node Modules for Node.js - http
, https
, http2
require("request-apis").constants.PROTOCOL_NODE_MODULES
List of Different HTTP Content Type value options for HTTP
require("request-apis").constants.CONTENT_TYPE
Contributions, Feature Improvements, Bugs, and Issues are invited. raising an issue