Giter Club home page Giter Club logo

nanorequest's Introduction

nanorequest stability

npm version build status downloads js-standard-style

Sometimes you just want to make a small request with a callback.

About

Sometimes, when you're testing an API for example, request is too large to install as as devDependency. Or might you don't need hawk authentication? Perhaps you're just sending JSON so you don't really care about multipart/mime (although this can handle that, you just gotta do the work yourself...).

This is not a full-featured library for sending and working with HTTP requests though. If you need something that isn't supported, you're likely looking at the wrong library. The idea here to really just wrap the built-in http.request method so you can use a callback and not deal with all the events crap.

Version 2.0.0 and higher requires node 8. If you want to use node 7 or earlier, you can continue to use ^1.0.0.

Installation

npm install nanorequest

Usage

const request = require('nanorequest')
// or!
import { nanorequest } from 'nanorequest'

const opts = {
  url: 'https://google.com'
}

const req = request(opts, (err, res, body) => {
  // do something with these things
})

// or with promises
request(opts)
  .then(({res, body}) => {}) // do something with these things
  .catch((err) => {}) // error out!

// or with async/await
try {
  const {res, body} = request(opts)
} catch (err) {
  console.log(err, err.res.statusCode, err.body)
}

API

nanorequest(opts:object(key:string), cb(err:Error, res:Response, body:(mixed)):function):Request|Promise

The opts object matches the options used in http.request, but accepts an optional url field.

  • opts.url:string - the URL you want to request. Will be parsed with url.parse.

The final parameter to the callback will depend on the content-type header returned from the server:

  • application/json: this will be parsed and the object will returned
  • text/*: the buffer will be converted to a string and returned
  • otherwise a buffer will be returned

If the callback is omitted, the function with return a Promise instead of returning the request.

License

Apache-2.0 ยฉ 2018 Todd Kennedy

nanorequest's People

Contributors

jgravois avatar toddself avatar ungoldman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nanorequest's Issues

version issues

Hi @toddself ๐Ÿ‘‹

Doing some maintenance and I noticed that there are a few issues with upgrading nanorequest from a consumer perspective:

  • latest version in master is v3.0.0
  • latest tag in releases is v2.0.3
  • latest version on npm is v4.0.1

In short: I have no idea what's going on! I'm unable to find a v4.0.0 let alone v4.0.1 in the source, so I'm quite wary of updating at all. Might you have some memory of what the version status for this fair repo is good sir?

Hope all's well otherwise, cheers from stumptown

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.