Giter Club home page Giter Club logo

jsonist's Introduction

jsonist

Build Status

JSON over HTTP: A simple wrapper around hyperquest for dealing with JSON web APIs.

NPM

A simple GET:

var url  = 'https://api.github.com/users/rvagg'
  , opts = { headers: { 'user-agent': 'yee haw grandma' } }
  , fn   = function (err, data) {
      console.log(data)
    }

jsonist.get(url, opts, fn)

// → { login: 'rvagg',
//     id: 495647,
//   ...
//   }

or a POST:

var url  = 'https://api.github.com/repos/rvagg/jsonist/issues'
  , opts = {
        headers : { 'user-agent': 'yee haw grandma' }
      , auth    : 'rvagg:24d5dee258c64aef38a66c0c5eca459c379901c2'
    }
  , data = {
        'title' : 'Not a bug'
      , 'body'  : 'Just guinea-pigging your repo dude, move along.'
    }
  , fn   = function (err, data) {
      console.log(data)
    }

jsonist.post(url, data, opts, fn)

// → { url: 'https://api.github.com/repos/rvagg/jsonist/issues/1',
//   ...
//   }

// you can also jsonist.put(), the kids love PUT requests these days

API

jsonist.get(url, [ options, ] callback)

Send a GET request to url and return the callback with an error or JSON deserialised data.

The options object is optional and is passed on to hyperquest.

jsonist.post(url, data, [ options, ] callback)

Send a POST request to url, writing JSON serialised data to the request, and return the callback with an error or JSON deserialised data (if any).

'method' is set to 'PUT' for you before passing on to hyperquest.

The options object is optional and is passed on to hyperquest.

jsonist.put(url, [ options, ] callback)

Same as jsonist.post() but for when that extra character is too much to type or you have to use someone's overloaded API. 'method' is set to 'PUT'.

Note: in each of the requests you can provide an optional 'hyperquest' parameter in your options if you want to really customise the http chain (see this)

License

jsonist is Copyright (c) 2014 Rod Vagg @rvagg and licensed under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.

jsonist's People

Contributors

rvagg avatar

Watchers

 avatar  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.