knucklebone

1.1.2 • Public • Published







knucklebone.js

Lightweight AJAX library for the client, intended for JSON API's

GitHub version


Overview of Knucklebone

Available Methods:

  • get()
  • getJson()
  • post()
  • postJson()
  • postUrlencoded()
knucklebone.getJson('path/to/file')
.success(json => console.log(json))
.error((err, res) => console.error(err));
knucklebone.postJson('url/path', jsonData)
.success(res => console.log(res))
.error((err, res) => console.error(err));

There are 2 methods that can handle the response(s):

  • success - receives any succesful responses
  • error - receives any errored responses and timeout responses

These methods are all chained onto the call--promise style. They both take a callback.

knucklebone.getJson("path/to/file")
.success(json => console.log(json))
.error((err, res) => console.error(err));

Get Parameters

Passing an object as a second parameter...

knucklebone.getJson("http://example.com", {
    name: "sam", token: "dn398fdh9eud0"
})

...would result in a query string of:

http://example.com?name=sam&token=dn398fdh9eud0

Headers

The third parameter passed to any knucklebone method can be an object of header info.

Example:

knucklebone.getJson("http://example.com", null, {
  withCredentials: true,
  'Content-Type': 'application/json;charset=UTF-8'
})


Why the name "knucklebone"?

This is why.

Package Sidebar

Install

npm i knucklebone

Weekly Downloads

7

Version

1.1.2

License

MIT

Last publish

Collaborators

  • same