LofoCats API is a simple API built with Ruby on Rails 🐈
1.1K
LofoCats API is a simple API built with Ruby on Rails created for demo purposes. (There's also a simple application consuming it, built with Rails: LofoCats UI).
The API provides endpoints for interacting with a registry of lost and found cats.
GET /api/users Retrieves all users. Requires administrator priviledges.
GET /api/users/:id Retrieves a user. Requires administrator priviledges.
POST /api/users Creates a new user. Requires administrator priviledges.
PUT/PATCH /api/users/:id Updates a user. Requires administrator priviledges.
DELETE /api/users/:id Deletes a user. Requires administrator priviledges.
POST /api/sessions Creates an authentication token to be used for subsequent requests for authorization.
DELETE /api/sessions Deletes the previously authentication token. Requires signed in user.
GET /api/cat_entries Retrieves cat entries. Available for all users.
GET /api/cat_entries/:id Retrieves a cat entry. Available for all users.
POST /api/cat_entries Creates a new cat entry. Only for signed in users.
UPDATE /api/cat_entries/:id Updates a cat entry. Administrators can update all entries, signed in users can update only their own entries. Guests can't update any entry.
DELETE /api/cat_entries/:id Deletes a cat entry. Administrators can delete all entries, signed in users can delete only their own entries. Guests can't delete any entry.
GET /api/health Returns HTTP 200 and "OK" if the app is running. Else HTTP 500.
GET /api/health/database Returns HTTP 200 and "OK" if the current migration level can be read from the database. Else HTTP 500.
GET /api/health/migration Returns HTTP 200 and "OK" if database migration level matches db/migrations. Else HTTP 500.
GET /api/health/cache Returns HTTP 200 and "OK" if a value can be written to the cache. Else HTTP 500.
GET /api/health/all Returns HTTP 200 and "OK" if all checks passes. Else HTTP 500.
See health_check for more details.
GET /api/metrics Returns Prometheus-formatted application metrics.
In order to consume endpoints that require a signed in user (administrator or not) you must first obtain an authentication token by posting to the respective sessions endpoint described above. You have to use this token as the Authorization header of your requests to the desired endpoints.
docker-compose up to setup the environment.docker-compose run --rm api rake db:load_demo_data to load some demo data to the application.If you loaded the demo data, the following users are available:
| Password | Administrator | |
|---|---|---|
| [email protected] | administrator | Yes |
| [email protected] | user123456 | No |
| [email protected] | user123456 | No |
The application contains RSpec specs. To run the tests:
docker-compose -f docker-compose.test.yml -p lofocats_api_test upContent type
Image
Digest
Size
84.2 MB
Last updated
over 7 years ago
docker pull maxbrunet/lofocats_api