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

fluent-request

v1.2.1

Published

A fluent interface for HTTP requests in Node.js

Downloads

7

Readme

Build Status Coverage Status

fluent-request

A fluent interface for HTTP requests in Node.js

Table of Contents

request(options)

Sends a request with the specified options. The options may be a string or an object. If options is a string, it will be parsed immediately with url.parse(). If options is an object, it should have the following properties:

  • protocol: The transmission protocol (defaults to 'http:').
  • hostname: A domain name or IP address of the server (defaults to 'localhost').
  • port: The port of the server (defaults to 80 for http and 443 for https).
  • method: The request method (defaults to 'GET').
  • path: The request path including the query string (defaults to '/').
  • headers: An object containing the request headers (defaults to {}).
var request = require('fluent-request');

var options = {
  protocol: 'https:',
  hostname: 'api.github.com',
  port: 443,
  method: 'GET',
  path: '/repos/bakerface/fluent-request',
  headers: {
    'User-Agent': 'bakerface'
  }
};

request(options)
  .then(function(response) {
    // the http response object
  })
  .catch(function(reason) {
    // an error occurred
  });

request.del(options)

Sends a DELETE request with the specified options. This is a convenience method for request(options).withMethod('DELETE').

var request = require('fluent-request');

request.del('https://api.github.com')
  .withPath('/repos/bakerface/fluent-request')
  .withUserAgent('bakerface')
  .then(function(response) {
    // the http response object
  })
  .catch(function(reason) {
    // an error occurred
  });

request.get(options)

Sends a GET request with the specified options. This is a convenience method for request(options).withMethod('GET').

var request = require('fluent-request');

request.get('https://api.github.com')
  .withPath('/repos/bakerface/fluent-request')
  .withUserAgent('bakerface')
  .then(function(response) {
    // the http response object
  })
  .catch(function(reason) {
    // an error occurred
  });

request.head(options)

Sends a HEAD request with the specified options. This is a convenience method for request(options).withMethod('HEAD').

var request = require('fluent-request');

request.head('https://api.github.com')
  .withPath('/repos/bakerface/fluent-request')
  .withUserAgent('bakerface')
  .then(function(response) {
    // the http response object
  })
  .catch(function(reason) {
    // an error occurred
  });

request.merge(options)

Sends a MERGE request with the specified options. This is a convenience method for request(options).withMethod('MERGE').

var request = require('fluent-request');

request.merge('https://api.github.com')
  .withPath('/repos/bakerface/fluent-request')
  .withUserAgent('bakerface')
  .withJSON({
    name: 'fluent-request',
    description: 'A fluent interface for HTTP requests in Node.js'
  })
  .then(function(response) {
    // the http response object
  })
  .catch(function(reason) {
    // an error occurred
  });

request.patch(options)

Sends a PATCH request with the specified options. This is a convenience method for request(options).withMethod('PATCH').

var request = require('fluent-request');

request.patch('https://api.github.com')
  .withPath('/repos/bakerface/fluent-request')
  .withUserAgent('bakerface')
  .withJSON({
    name: 'fluent-request',
    description: 'A fluent interface for HTTP requests in Node.js'
  })
  .then(function(response) {
    // the http response object
  })
  .catch(function(reason) {
    // an error occurred
  });

request.post(options)

Sends a POST request with the specified options. This is a convenience method for request(options).withMethod('POST').

var request = require('fluent-request');

request.post('https://api.github.com')
  .withPath('/user/repos')
  .withUserAgent('bakerface')
  .withJSON({
    name: 'fluent-request',
    description: 'A fluent interface for HTTP requests in Node.js'
  })
  .then(function(response) {
    // the http response object
  })
  .catch(function(reason) {
    // an error occurred
  });

request.put(options)

Sends a PUT request with the specified options. This is a convenience method for request(options).withMethod('PUT').

var request = require('fluent-request');

request.put('https://api.github.com')
  .withPath('/repos/bakerface/fluent-request')
  .withUserAgent('bakerface')
  .withJSON({
    name: 'fluent-request',
    description: 'A fluent interface for HTTP requests in Node.js'
  })
  .then(function(response) {
    // the http response object
  })
  .catch(function(reason) {
    // an error occurred
  });

request.withContent(content)

Sets the content for the HTTP request. This must be UTF8 encoded string. This must be used in combination with withContentType.

var request = require('fluent-request');

request.patch('https://api.github.com')
  .withPath('/repos/bakerface/fluent-request')
  .withUserAgent('bakerface')
  .withContentType('application/json')
  .withContent('{"name":"fluent-request","description":"A fluent interface for HTTP requests in Node.js"}')
  .then(function(response) {
    // the http response object
  })
  .catch(function(reason) {
    // an error occurred
  });

request.withContentType(type)

Sets the 'Content-Type' header for the HTTP request. This must be used in combination with withContent.

var request = require('fluent-request');

request.patch('https://api.github.com')
  .withPath('/repos/bakerface/fluent-request')
  .withUserAgent('bakerface')
  .withContentType('application/json')
  .withContent('{"name":"fluent-request","description":"A fluent interface for HTTP requests in Node.js"}')
  .then(function(response) {
    // the http response object
  })
  .catch(function(reason) {
    // an error occurred
  });

request.withForm(form)

Sets the form content for the HTTP request. This is a convenience method for request.withContentType('application/x-www-form-urlencoded').withContent(url.encode(form)).

var request = require('fluent-request');

request.post('https://api.github.com')
  .withPath('/repos/bakerface/fluent-request')
  .withUserAgent('bakerface')
  .withForm({
    name: 'fluent-request',
    description: 'A fluent interface for HTTP requests in Node.js'
  })
  .then(function(response) {
    // the http response object
  })
  .catch(function(reason) {
    // an error occurred
  });

request.withHeader(key, value)

Sets the header for the HTTP request. The key must be a string. The value is transformed to a string with toString().

var request = require('fluent-request');

request.get('https://api.github.com')
  .withPath('/repos/bakerface/fluent-request')
  .withHeader('User-Agent', 'bakerface')
  .then(function(response) {
    // the http response object
  })
  .catch(function(reason) {
    // an error occurred
  });

request.withJSON(json)

Sets the JSON content for the HTTP request. This is a convenience method for request.withContentType('application/json').withContent(JSON.stringify(json)).

var request = require('fluent-request');

request.patch('https://api.github.com')
  .withPath('/repos/bakerface/fluent-request')
  .withUserAgent('bakerface')
  .withJSON({
    name: 'fluent-request',
    description: 'A fluent interface for HTTP requests in Node.js'
  })
  .then(function(response) {
    // the http response object
  })
  .catch(function(reason) {
    // an error occurred
  });

request.withMethod(method)

Sets the method for the HTTP request. This function allows for custom HTTP verbs that are not supplied as a convenience function.

var request = require('fluent-request');

request('https://api.github.com')
  .withMethod('PATCH')
  .withPath('/repos/bakerface/fluent-request')
  .withUserAgent('bakerface')
  .withJSON({
    name: 'fluent-request',
    description: 'A fluent interface for HTTP requests in Node.js'
  })
  .then(function(response) {
    // the http response object
  })
  .catch(function(reason) {
    // an error occurred
  });

request.withPath(path)

Sets the path for the HTTP request. This must not include the query string.

var request = require('fluent-request');

request.patch('https://api.github.com')
  .withPath('/repos/bakerface/fluent-request')
  .withUserAgent('bakerface')
  .withJSON({
    name: 'fluent-request',
    description: 'A fluent interface for HTTP requests in Node.js'
  })
  .then(function(response) {
    // the http response object
  })
  .catch(function(reason) {
    // an error occurred
  });

request.withPathSection(index, section)

Modifies the path for the HTTP request by changing a section of the path.

var request = require('fluent-request');

request.patch('https://api.github.com')
  .withPath('/repos/bakerface/:repo')
  .withPathSection(2, 'fluent-request')
  .withUserAgent('bakerface')
  .withJSON({
    name: 'fluent-request',
    description: 'A fluent interface for HTTP requests in Node.js'
  })
  .then(function(response) {
    // the http response object
  })
  .catch(function(reason) {
    // an error occurred
  });

request.withUserAgent(userAgent)

Sets the 'User-Agent' header for the HTTP request.

var request = require('fluent-request');

request.patch('https://api.github.com')
  .withPath('/repos/bakerface/fluent-request')
  .withUserAgent('bakerface')
  .withJSON({
    name: 'fluent-request',
    description: 'A fluent interface for HTTP requests in Node.js'
  })
  .then(function(response) {
    // the http response object
  })
  .catch(function(reason) {
    // an error occurred
  });

request.withQuery(key, value)

Sets the query parameter for the HTTP request. The key must be a string. The value is transformed to a string with toString().

var request = require('fluent-request');

request.get('https://api.github.com')
  .withPath('/user/repos')
  .withQuery('page', 1)
  .withQuery('per_page', 100)
  .withUserAgent('bakerface')
  .then(function(response) {
    // the http response object
  })
  .catch(function(reason) {
    // an error occurred
  });