hoodie-client
Hoodie’s client for the browser
Hoodie’s client glue code that integrates Hoodie’s client core modules: account, store and task
Example
var Hoodie = var hoodie = options hoodieaccount
API
- Constructor
- hoodie.url
- hoodie.account
- hoodie.store
- hoodie.task
- hoodie.connectionStatus
- hoodie.log
- hoodie.request
- hoodie.plugin
- hoodie.reset
- hoodie.on
- hoodie.one
- hoodie.off
- hoodie.trigger
- Events
Constructor
options
Argument | Type | Description | Required |
---|---|---|---|
options.url | String | Set to hostname where Hoodie server runs, if your app runs on a different host | No |
options.account | String |
account options.
options.url is always set to hoodie.url + '/account/api'
|
No |
options.store | String |
store options.
options.dbName is always set to hoodie.account.id .
options.remote is always set to hoodie.url + '/store/api'
|
No |
options.task | String |
task options.
options.userId is always set to hoodie.account.id .
options.remote is always set to hoodie.url + '/task/api'
|
No |
options.connectionStatus | String |
connectionStatus options.
options.url is always set to hoodie.url + '/connection-status/api'.
options.method is always set to HEAD
|
No |
hoodie.url
Read-only
hoodieurl
full url to the hoodie server, e.g. http://example.com/hoodie
hoodie.account
hoodie.account
is an instance of hoodie-account-client.
See account API
hoodie.store
hoodie.store
is an instance of hoodie-store.
See store API
hoodie.task
hoodie.task
is an instance of hoodie-client-task.
See task API
hoodie.connectionStatus
hoodie.connectionStatus
is an instance of hoodie-connection-status.
See connectionStatus API
hoodie.log
hoodie.log
is an instance of hoodie-log.
See log API
hoodie.request
Sends an http request
hoodie// orhoodie
Argument | Type | Description | Required |
---|---|---|---|
url | String |
Relative path or full URL. A path must start with / and sends a GET
request to the path, prefixed by hoodie.url . In case a full URL is passed,
a GET request to the url is sent.
|
Yes |
options.url | String |
Relative path or full URL. A path must start with / and sends a GET
request to the path, prefixed by hoodie.url . In case a full URL is passed,
a GET request to the url is sent.
|
Yes |
options.method | String |
Defaults to GET . One of GET ,
HEAD , POST , PUT , DELETE .
|
No |
options.data | Object, Array, String or Number |
For PUT and POST requests, an optional payload
can be sent. It will be stringified before sending the request.
|
No |
options.headers | Object | Map of Headers to be sent with the request. | No |
options.data | Object, Array, String or Number |
For PUT and POST requests, an optional payload
can be sent. It will be stringified before sending the request.
|
No |
Examples
// sends a GET request to hoodie.url + '/foo/api/bar'hoodie// sends a GET request to another hosthoodie// sends a PATCH request to /foo/api/barhoodie
hoodie.plugin
Initialise hoodie plugin
hoodiehoodie
Argument | Type | Description | Required |
---|---|---|---|
methods | Object |
Method names as keys, functions as values. Methods get directly set on
hoodie , e.g. hoodie.plugin({foo: function () {}})
sets hoodie.foo to function () {}
|
Yes |
plugin | Function | The passed function gets called with `hoodie` as first argument, and can directly set new methods / properties on it. | Yes |
Examples
hoodiehoodie
hoodie.reset
🐕 TO BE DONE: #12
Reset hoodie client and emit reset
event so plugins can reset as well.
hoodie
Resolves without argument.
hoodie.on
Subscribe to event.
hoodie
Example
hoodie
hoodie.one
Call function once at given event.
hoodie
Example
hoodiehoodiehoodie// logs "foo is bar"// DOES NOT log "foo is baz"
hoodie.off
Removes event handler that has been added before
hoodie
Example
hoodie
hoodie.trigger
Trigger custom events
hoodie
Example
hoodie
Events
reset |
triggered when hoodie.reset() succeeded |
---|---|
account:* |
events, see account events |
store:* |
events, see store events |
task:* |
events, see task events |
connectionStatus:* |
events, see connectionStatus events |
Testing
Local setup
git clone https://github.com/hoodiehq/hoodie-client.git
cd hoodie-client
npm install
Run all tests
npm test
Run test from one file only
node tests/specs/id