Overview

This is the demo app for the ApiSampler gem. It is intended to explain basic usage of the gem along with some configuration options.

Go to endpoints to see which requests generate samples. Go to ApiSampler to manage collected samples.

Info
This app is reset daily.

Config

This app has ApiSampler configured with the following options:

# File: config/initializers/api_sampler.rb

ApiSampler.configure do |config|
  # Collect samples for requests to enpoints which have path starting with "/api/v1/"
  config.allow(%r{^/api/v1/.*})

  # Exclude the :format parameter from collected samples
  config.path_params_blacklist << :format

  # Tag samples of requests which took more than 1 second to complete as slow
  config.tag_with(:slow, color: 'red') do |request|
    request.env['api_sampler_demo.elapsed_time'] > 1.second
  end

  # Limit collected samples to 10 samples per 5 minutes
  config.samples_quota count: 10, per: 5.minutes
end
Info
See the docs for detailed information about configuration.

Endpoints

This app provides a simple RESTful resource named Product with a single text field name in addition to the obligatory id and timestamps.

Info

All endpoints accept a delay in seconds as the sleep query parameter to simulate slow requests. The following example demonstrates how to force the application to wait for two seconds before serving the request.

$ curl -H "Content-Type: application/json" -X GET \
    https://api-sampler-demo.herokuapp.com/api/v1/products?sleep=2
[{"id":3,"name":"Cereal","created_at":"2016-11-08T12:01:16.922Z","updated_at":"2016-11-08T12:01:16.922Z","url":"https://api-sampler-demo.herokuapp.com/api/v1/products/3"},{"id":4,"name":"Milk","created_at":"2016-11-08T12:14:32.953Z","updated_at":"2016-11-08T12:14:32.953Z","url":"https://api-sampler-demo.herokuapp.com/api/v1/products/4"}]

GET /api/v1/products

Return a list of all products.

Get all products.
$ curl -H "Content-Type: application/json" -X GET \
    https://api-sampler-demo.herokuapp.com/api/v1/products
[{"id":3,"name":"Cereal","created_at":"2016-11-08T12:01:16.922Z","updated_at":"2016-11-08T12:01:16.922Z","url":"https://api-sampler-demo.herokuapp.com/api/v1/products/3"},{"id":4,"name":"Milk","created_at":"2016-11-08T12:14:32.953Z","updated_at":"2016-11-08T12:14:32.953Z","url":"https://api-sampler-demo.herokuapp.com/api/v1/products/4"}]

POST /api/v1/products

Create a new product.

Create a new product with name «Cereal».
$ curl -H "Content-Type: application/json" -X POST \
    -d '{ "product": { "name": "Cereal" } }' \
    https://api-sampler-demo.herokuapp.com/api/v1/products
{"id":3,"name":"Cereal","created_at":"2016-11-08T12:01:16.922Z","updated_at":"2016-11-08T12:01:16.922Z","url":"https://api-sampler-demo.herokuapp.com/api/v1/products/3"}

GET /api/v1/products/:id

Get a single product.

Get the product with id «3».
$ curl -H "Content-Type: application/json" -X GET \
     https://api-sampler-demo.herokuapp.com/api/v1/products/3
{"id":3,"name":"Cereal","created_at":"2016-11-08T12:01:16.922Z","updated_at":"2016-11-08T12:01:16.922Z","url":"https://api-sampler-demo.herokuapp.com/api/v1/products/3"}

PATCH /api/v1/products/:id

Update the product with the given id.

Set name of the product with id «4» to «Strawberry Milk».
$ curl -H "Content-Type: application/json" -X PATCH \
     -d '{ "product": { "name": "Strawberry Milk" } }' \
     https://api-sampler-demo.herokuapp.com/api/v1/products/4
{"id":4,"name":"Strawberry Milk","created_at":"2016-11-08T12:14:32.953Z","updated_at":"2016-11-08T12:22:54.418Z","url":"https://api-sampler-demo.herokuapp.com/api/v1/products/4"}

DELETE /api/v1/products/:id

Delete the product with the given id.

Delete the product with id «4».
$ curl -H "Content-Type: application/json" -X DELETE \
    https://api-sampler-demo.herokuapp.com/api/v1/products/4