Skip to content

iridakos/lofocats_api

Repository files navigation

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.

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 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:

Email Password Administrator
administrator@lofocats.com administrator Yes
user@lofocats.com user123456 No
another_user@lofocats.com user123456 No

Testing

The application contains RSpec specs. To run the tests:

  • Execute rake db:test:prepare
  • Execute rspec

TODO

  • Document request parameters & responses

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages