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.
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.
- Clone the repository.
- Execute
bundle install
to install the required gems. - Execute
rake db:setup
to setup the database. - Execute
rake db:load_demo_data
to load some demo data to the application. - Execute
rails server
to start the application on the default port.
If you loaded the demo data, the following users are available:
Password | Administrator | |
---|---|---|
administrator@lofocats.com | administrator | Yes |
user@lofocats.com | user123456 | No |
another_user@lofocats.com | user123456 | No |
The application contains RSpec specs. To run the tests:
- Execute
rake db:test:prepare
- Execute
rspec
- Document request parameters & responses