npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

default-http

v0.0.2

Published

Simple class to manage http request and response in multiple project

Downloads

55

Readme

Default-http

This is just a repository to factor classes that I always use in my web projects as an abstraction for every "req" and "res" object in Restify, Koa, Hapi and Express.

/**
 * This is a standard HttpRequest object that aims to be used in any web server framework
 */
export default class HttpRequest {

  /**
   * This creates need a new HttpRequest
   * @param  {string} method   The is the method attribute
   * @param  {Object} body     The is the body of the request
   * @param  {Object[]} cookies  The is the cookie array of the request
   * @param  {string} hostname This is hostname
   * @param  {string} ip       The sending ip
   * @param  {string} url      The request url
   * @param  {Object} params   The url params of the request
   * @param  {string} path     The request path
   * @param  {string} protocol The request protocol
   * @param  {Object} query    The query params of the request
   * @param  {boolean} secure   Is the request secure ?
   * @param  {Object} headers  The request headers
   */
  constructor (method, body, cookies, hostname, ip, url, params, path, protocol, query, secure, headers, req) {
    /**
     * The is the method attribute
     * @type {string}
     */
    this.method = method
    /**
     * The is the body of the request
     * @type {Object}
     */
    this.body = body
    /**
     * The is the cookie array of the request
     * @type {Object}
     */
    this.cookies = cookies
    /**
     * This is hostname
     * @type {string}
     */
    this.hostname = hostname
    /**
     * The sending ip
     * @type {string}
     */
    this.ip = ip
    /**
     * The request url
     * @type {string}
     */
    this.url = url
    /**
     * The url params of the request
     * @type {Object}
     */
    this.params = params
    /**
     * The request path
     * @type {string}
     */
    this.path = path
    /**
     * The request protocol
     * @type {string}
     */
    this.protocol = protocol
    /**
     * The query params of the request
     * @type {Object}
     */
    this.query = query
    /**
     * Is the request secure ?
     * @type {boolean}
     */
    this.secure = secure
    /**
     * The request headers
     * @type {Object}
     */
    this.headers = headers
    /**
     * The default request from the server
     * @type {Object}
     */
    this.req = req
  }
}
import Constants from './constants'
import Errors from './errors'
/**
 * This is a standard HttpResponse object that aims to be used in any web server framework
 */
export default class HttpResponse {

  /**
   * Create a new standard HttpResponse
   * @param  {Object} content Object that could have both content or page property
   * @param  {number} code    The http code of the request
   * @param  {Object} headers The response headers
   */
  constructor (content, code, headers) {
    if (content && !content.content && !content.page) throw new Error(Errors.NO_CONTENT)
    /**
     * The http code of the request
     * @type {number}
     */
    this.code = code ? code : 200 // eslint-disable-line no-unneeded-ternary
    /**
     * Object that could have both content or page property
     * @type {Object}
     */
    this.content = content ? content : {content: Constants[this.code]} // eslint-disable-line no-unneeded-ternary
    /**
     * The response headers
     * @type {Object}
     */
    this.headers = headers
  }
}