Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A web API using Sinatra and Redis to track my daily coffee consumption

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 conf
Octocat-spinner-32 log
Octocat-spinner-32 test
Octocat-spinner-32 views
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rvmrc
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 Procfile
Octocat-spinner-32 Rakefile
Octocat-spinner-32 coffee_tracker.rb


A simple web service to track the number of cups of coffee I consume each day.

 Configuring Redis

Redis is the sole datastore for this app.

If deploying to Heroku, the free RedisToGo addon can be used thus:

$ heroku addons:add redistogo:nano

For other situations you may want to modify conf/redis.rb accordingly.

API keys

Write access to the service is controlled via API key. The key is specified in the X-API-Key header when POSTing to the service. A request with missing or invalid key will receive a 4xx response code.

Specifying an API key

Add the desired key to the api_keys set:

$ redis-cli
redis> SADD api_keys YOUR_API_KEY
(integer) 1

Checking API keys

redis> SMEMBERS api_keys


Assuming Redis is installed and running locally:

$ git clone .
$ bundle install
$ bundle exec rackup

Web interface is then available at


The test suite uses Minitest which is now part of the Ruby 1.9.x standard library and can be kicked off with Rake:

$ bundle exec rake


GET /api

Retrieves the current count:

$ curl

POST /api

Updates the count, returning the updated count in the response body as text/plain:

$ curl -X POST -d '' -H X-API-Key:YOUR_API_KEY
Something went wrong with that request. Please try again.