# hello.js
[![CDNJS](https://img.shields.io/cdnjs/v/hellojs.svg)](https://cdnjs.com/libraries/hellojs/)
A client-side JavaScript SDK for authenticating with [OAuth2](http://tools.ietf.org/pdf/draft-ietf-oauth-v2-12.pdf) (and **OAuth1** with a [oauth proxy](#oauth-proxy)) web services and querying their REST APIs. HelloJS standardizes paths and responses to common APIs like Google Data Services, Facebook Graph and Windows Live Connect. It's **modular**, so that list is [growing](./modules). No more spaghetti code!
## E.g.
name |
type |
example |
description |
argument |
default |
path |
string |
/me ,
/me/friends
|
A relative path to the modules base URI, a full URI or a mapped path defined by the module - see REST API. |
required
|
null |
query |
object |
{name:Hello }
|
HTTP query string parameters. |
optional
|
null |
method |
get ,
post ,
delete ,
put
|
See
type
|
HTTP request method to use. |
optional
|
get
|
data |
object |
{name:Hello , description:Fandelicious }
|
A JSON object of data, FormData, HTMLInputElement, HTMLFormElment to be sent along with a
get ,
post or
put request
|
optional
|
null
|
timeout |
integer |
3000 = 3 seconds.
|
Wait milliseconds before resolving the Promise with a reject.
|
optional
|
60000
|
callback |
function |
function(json){console.log(json);}
|
A function to call with the body of the response returned in the first parameter as an object, else boolean false.
|
optional
|
null
|
More options (below) require putting the options into a 'key'=>'value' hash. I.e. hello(network).api(options)
|
formatResponse |
boolean |
false
|
true : format the response, false : return raw response.
|
optional
|
true
|
### Examples:
```js
hello('facebook').api('me').then(function(json) {
alert('Your name is ' + json.name);
}, function(e) {
alert('Whoops! ' + e.error.message);
});
```
# Event Subscription
Please see [demo of the global events](demos/events.html).
## hello.on()
Bind a callback to an event. An event may be triggered by a change in user state or a change in some detail.
### hello.on(event, callback)