knucklebone
v1.1.2
Published
Lightweight AJAX library for the client
Downloads
2
Maintainers
Readme
knucklebone.js
Lightweight AJAX library for the client, intended for JSON API's
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 responseserror
- 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.