A RESTHooks.org reference implementation in Ruby / Rails.
Ruby JavaScript CSS
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
bin
config
db
lib
log
public
spec
vendor/assets
.gitignore
.rspec
Gemfile
Gemfile.lock
Guardfile
Procfile
README.md
Rakefile
config.ru

README.md

RESTHooks

Stop polling

http://resthooks.herokuapp.com/

Create resources

All requests must contain HTTP_AUTHORIZATION header with "Token token="USER-TOKEN-PREVIOUSLY-PROVIDED""

There are two main resources. They are called Beers and burgers, and both have a deliciousness field.

Create beers and burgers

All examples will use beers. For burgers, please replace beers and use burgers instead.

You can create beers by posting to /api/v1/beers with the following payload:

{
  "beer": {
    "deliciousness": 3
  }
}
Example using curl
curl "http://localhost/api/v1/beers" \
  -H 'Accept: application/json' -H 'Content-type: application/json' \
  -H "Authorization: Token token=TOKEN-HERE" \
  -X POST \
  -d '{
        "beer": {
          "deliciousness": 3
        }
      }'

Update beers and burgers

You can update them by putting to /api/v1/beers/ID with the following payload:

{
  "beer": {
    "deliciousness": 4
  }
}
Example using curl
curl "http://localhost/api/v1/beers/1" \
  -H 'Accept: application/json' -H 'Content-type: application/json' \
  -H "Authorization: Token token=TOKEN-HERE" \
  -X PUT \
  -d '{
        "beer": {
          "deliciousness": 4
        }
      }'

Using the resthooks for your service

So now you've got beers and burgers, your service can be subscribed to receive updates when they get modified/created/destroyed.

You need to post to /api/v1/resource_subscriptions (user token in header)

{
  "resource_subscription": {
    "post_url": "https://example.com/some_hook?user_id=123",
    "authentication": null,
    "version": 1,
    "resource": "beer"
  }
}
Example using curl
curl "http://localhost/api/v1/resource_subscriptions
  -H 'Accept: application/json' -H 'Content-type: application/json' \
  -H "Authorization: Token token=TOKEN-HERE" \
  -X PUT \
  -d '{
    "resource_subscription": {
      "post_url": "https://example.com/some_hook?user_id=123",
      "authentication": null,
      "version": 1,
      "resource": "beer"
    }
  }'

LICENSE

MIT 2013.