GithubHelp home page GithubHelp logo

ganeshkbhat / apis-request Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 453 KB

npm module with APIs for cleaner request and basic http requests utils. Contains constants for protocols, http headers, methods, and content types

License: MIT License

JavaScript 100.00%
api apis concurrency constants content-types delete get headers http http-headers

apis-request's Introduction

request-apis

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

Usage:

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

All request-apis Methods:

request

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 }> 
 * 
 */

getRequest

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 }> 
 * 
 */

postRequest

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 }> 
 * 
 */

putRequest

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 }>
 * 
 */

patchRequest

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 }> 
 * 
 */

deleteRequest

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 }> 
 * 
 */

optionsRequest

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 }> 
 * 
 */

contentTypeHandler

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 }
 */

checkHttpsProtocol

Check and get type of protocol - http or https

.checkHttpsProtocol(url)

/**
 *
 * @param {*} url
 * @return {*} Boolean
 * 
 */

getProtocol

Check and Get the protocol of the url.

.getProtocol(url)

/**
 *
 * @param {*} url
 * @return {*} Boolean
 * 
 */

isValidURL

Is the url a valid url structure.

.isValidURL(url)

/**
 *
 * @param {*} url
 * @return {*} Boolean
 * 
 */

DIFFERENT HTTP CONSTANTS

Different HTTP Constants associated to the package provided as an JS Object. Can be useful for testing/ automated testing purposes, etc.

REQUEST_HEADERS

List of Different HTTP Request headers for HTTP

require("request-apis").constants.REQUEST_HEADERS

REQUEST_HEADERS_CATEGORIZED

List of Different HTTP Request headers categorized for HTTP

require("request-apis").constants.REQUEST_HEADERS_CATEGORIZED

RESPONSE_HEADERS

List of Different HTTP Response headers for HTTP

require("request-apis").constants.RESPONSE_HEADERS

RESPONSE_HEADERS_CATEGORIZED

List of Different HTTP Response headers categorized for HTTP

require("request-apis").constants.RESPONSE_HEADERS_CATEGORIZED

PROTOCOLS

List of Different HTTP Protocols for Node.js - http, https

require("request-apis").constants.PROTOCOLS

PROTOCOL_NODE_MODULES

List of Different HTTP Node Modules for Node.js - http, https, http2

require("request-apis").constants.PROTOCOL_NODE_MODULES

CONTENT_TYPE

List of Different HTTP Content Type value options for HTTP

require("request-apis").constants.CONTENT_TYPE

Contributions

Contributions, Feature Improvements, Bugs, and Issues are invited. raising an issue

License

MIT License

apis-request's People

Contributors

ganeshkbhat avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.