Hook.Client Class
Hook.Client is the entry-point for using hook.
You should instantiate a global javascript client for consuming hook.
var client = new Hook.Client({
url: "http://local-or-remote-hook-address.com/public/index.php/",
app_id: 1, // your app's id
key: 'test' // your app's public key
});
Item Index
Methods
Methods
channel
(
Hook.Channel
-
name
-
options
Get channel instance.
Parameters:
-
name
String -
options
Object(optional)
Returns:
Hook.Channel:
Example:
Create a channel using Servet-Sent Events transport.
var channel = client.channel('messages');
Create a channel using WebSockets transport.
var channel = client.channel('messages', { transport: "websockets" });
collection
(
Hook.Collection
-
collectionName
Get collection instance.
Parameters:
-
collectionName
String
Returns:
Example:
Retrieve a collection reference. Your collection tables are created on demand.
// Users collection
var users = client.collection('users');
// Highscores
var highscores = client.collection('highscores');
delete
(
-
segments
Delete existing resource.
Parameters:
-
segments
String
get
(
-
segments
-
data
Retrieve a resource
Parameters:
-
segments
String -
data
Object
getHeaders
()
Object
Get XHR headers for app/auth context.
Returns:
Object:
getPayload
(
String | FormData
-
requestMethod
-
data
Get payload of given data
Parameters:
-
requestMethod
String -
data
Object
Returns:
String | FormData:
post
(
-
segments
-
data
Create resource
Parameters:
-
segments
String -
data
Object
put
(
-
segments
-
data
Update existing resource
Parameters:
-
segments
String -
data
Object
request
(
-
segments
-
method
-
data
Parameters:
-
segments
String -
method
String -
data
Object
url
(
String
-
route
Get remote URL string.
Parameters:
-
route
String
Returns:
String:
Example:
Downloading data from a hook route
location.href = client.url('download', { something: "hey" })
Using custom hook route for image catpcha
// Implementing custom route for captcha: https://github.com/doubleleft/hook/wiki/Composer-dependencies
var img = new Image();
img.src = client.url('captcha');