Sign inSign up

maxbrunet/lofocats_api

By maxbrunet

•Updated over 7 years ago

LofoCats API is a simple API built with Ruby on Rails 🐈

Image
0

1.1K

maxbrunet/lofocats_api repository overview

⁠LofoCats API

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⁠).

⁠Functionality

The API provides endpoints for interacting with a registry of lost and found cats.

⁠Endpoints

⁠Users

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.

⁠Session

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.

⁠Cat entries

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.

⁠Monitoring

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.

⁠Authentication & Authorization

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.

⁠Setting up the application

  • Clone the repository.
  • Execute docker-compose up to setup the environment.
  • Execute 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:

EmailPasswordAdministrator
[email protected]administratorYes
[email protected]user123456No
[email protected]user123456No

⁠Testing

The application contains RSpec specs. To run the tests:

  • Execute docker-compose -f docker-compose.test.yml -p lofocats_api_test up

⁠TODO

  • Document request parameters & responses

Tag summary

Content type

Image

Digest

Size

84.2 MB

Last updated

over 7 years ago

docker pull maxbrunet/lofocats_api