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

extended-request

v1.6.1

Published

An enhanced request module for node.js for REST-/API servers.

Downloads

20

Readme

extended-request

GitHub license Build Status npm version

An enhanced request module for node.js for REST-/API servers.

Features:

  • Supports various auth providers (Basic, Bearer, Token, PostToken, Custom ..)
  • Supports HTTP and HTTP/S (TLS) protocols
  • Auto response content-type negotiation (JSON, HTML, Plain, ...)
  • GZIP compression
  • ES6 & ES5 support
  • Promises & classic nodeback
  • Debugging

Table of contents


API Reference

ExtendedRequest(
    [Object {
        host: String='',
        port: Number='',
        endpoint: String='',
        auth: Object { 
            provider: String='basic|bearer|token|postToken|custom',
            username: String='',
            password: String='',
            token: String='',
            custom: String=''
        }
    } details]
) -> Object {
    /* Constants */
    this:  Object=this,

    /* Methods */
    request:  [String=path, Object {
        method: String='GET|POST|HEAD|...',
        type: String='text/plain|application/json|...',
        bodyType: String='application/x-www-form-urlencoded|application/json|...',
        body: String='',
    } options, function(class ErrorClass err, null ok) cb] | Promise
}

/* Statics */

ExtendedRequest.DEBUG = true/false

Property reference:

| Property | Description | | ------ | ----------- | | details | An object with some connection details | | options | An object containing request options | | host | FQDN used for requests (eg. myapi.com) | | port | Default = 80 | | 443 enables https | | path | URI path (eg. /get/users) | endpoint | host endpoint/prefix for a path (eg. /api/v1) | type | The HTTP Content-Type for the request. Check lib/util.js for valid types Default is BT.JSON | body | POST payload | bodyType | The type of the body payload. Check lib/util.js for valid types. Default is BT.FORM | auth | Authentication details | |.provider = Either 'basic, bearer, token, postToken, custom' | | |.username = Set HTTP basic auth username when provider is 'basic' | | |.password = Set HTTP basic auth password when provider is 'basic' | | |.token = Set HTTP auth token (header) when provider is 'token' or 'bearer'. Set POST token when provider is 'postToken' and request.method is 'POST' | | |.custom = Set HTTP auth header when provider is 'custom' |


Function reference:

Creating a request container

Available options:

| | | Required | | ------ | ----------- | ------ | | host | FQDN (eg. myapi.com) | Yes | | port | Port | No | | endpoint | Path prefix | No | | auth | Authentication details | No |

const api = new ExtendedRequest({
  host: 'jsonplaceholder.typicode.com',
  port: 443
})

Performing a request

Available options:

| | | Required | | ------ | ----------- | ------ | | method | HTTP method (Default: GET) | No | | type | Content-Type (Default: 'application/json') | No | | body | Body for a post request | If method is 'POST' | | bodyType | Set specific type (Default: 'application/x-www-form-urlencoded')| No| | headers | Set optional headers object | No|

api.request('/posts/1', (err, response) => {
  console.log(err, response)
})

api.request('/store/post', {
  method: 'POST',
  body: 'My new Post!'
}, (err, response) => {
  console.log(err, response)
})

/* Promises */

api.request('/posts/1')
.then((response) => {
  console.log(response)
})
.catch((err) => {
  console.log(err)
})

api.request('/store/post', {
  method: 'POST',
  body: 'My new Post!'
})
.then((response) => {
  console.log(response)
})
.catch((err) => {
  console.log(err)
})

Setup / Install

Use npm install @burnett01/extended-request

// ES6
import ExtendedRequest from '@burnett01/extended-request'

// ES5
var ExtendedRequest = require('@burnett01/extended-request')

Build

NPM

npm run build

Make

make build


Unit-Tests

The testing-framework used by this module is Mocha with the BDD / TDD assertion library Chai.

  • test/test.default.js Performs 9 tests | Source

Default reporter: list

Make

make test

NPM

npm test


Contributing

You're very welcome and free to contribute. Thank you.


License

MIT