/my_beers

My Beers API

Primary LanguageRubyMIT LicenseMIT

MyBeers

codebeat badge Test Coverage Ruby

About this project

This project is a example to use:

  • Is a Rails Application API-only. This API gives 3 resources:
    • Pubs
    • Beers
    • Styles
  • Secured by HTTP Basic Authentication
  • User mode, with different roles (admin, user, guest)
  • CRUD
  • Limit access to given part of API depending on User role:
    • Admin has access to everything
    • User can read all, create all, but update and deleted only his records
    • Guest has only read access

Technical Informations and dependencies

* The Ruby language   # version 2.7.0
* The Rails gem       # version 6.0
* RSpec               # version 4.0.0
* Rubocop             # version 0.84.0
* PostgreSQL          # version 10
* Docker              # version 19.03.8-ce
* Docker Compose      # version 1.25.5

To use

Clone the project:

git clone git@github.com:marcelotoledo5000/my_beers.git
cd my_beers

With Docker (better option)

script/setup    # => development bootstrap, preparing containers
script/server   # => starts server
script/console  # => starts console
script/test     # => running tests

Running without Docker (not recommended!)

If you prefer, you'll need to update config/database.yml:

# host: db        # when using docker
host: localhost   # when using localhost

System dependencies

And then:

gem install bundler         # => install the last Bundler version
bundle install              # => install the project's gems
rails db:setup db:migrate   # => prepare the database
rails s                     # => starts server
rails c                     # => starts console
bundle exec rspec           # => to running tests

To run app

To see the application in action, starts the rails server to able http://localhost:3000/

Dockerfile

Dockerfile is here

API Documentation

Authentication

  • Needs to use HTTP Basic Authentication.

The format of a WWW-Authenticate header for HTTP basic authentication is:

WWW-Authenticate: Basic realm="Our Site"

Domain

http://localhost:3000/ Header with: user = email, pass = password

Endpoints

PUBS

INDEX

GET: http://DOMAIN/pubs
"http://localhost:3000/pubs"

Response:

200 Ok

SHOW

GET: http://DOMAIN/pubs/ID
"http://localhost:3000/pubs/1"

Response:

200 Ok

CREATE

POST: http://DOMAIN/pubs
"http://localhost:3000/pubs"
Params: Body, JSON(application/json)
{
  "name": "Delirium Cafe",
  "country": "Belgium",
  "state": "BE",
  "city": "Brussels",
  "user_id": 1
}

Response:

201 Created

UPDATE

PUT: http://DOMAIN/pubs/ID
"http://localhost:3000/pubs/1"
Params: Body, JSON(application/json)
{
  "name": "BrewDog"
}

Response:

204 No Content

DESTROY

DELETE: http://DOMAIN/pubs/ID
"http://localhost:3000/pubs/2"

Response:

204 No Content
STYLES

INDEX

GET: http://DOMAIN/styles
"http://localhost:3000/styles"

Response:

200 Ok

SHOW

GET: http://DOMAIN/styles/ID
"http://localhost:3000/styles/1"

Response:

200 Ok

CREATE

POST: http://DOMAIN/styles
"http://localhost:3000/styles"
Params: Body, JSON(application/json)
{
  "name": "German-Style Schwarzbier",
  "school_brewery": "German",
  "user_id": 1
}

Response:

201 Created

UPDATE

PUT: http://DOMAIN/styles/ID
"http://localhost:3000/styles/1"
Params: Body, JSON(application/json)
{
  "name": "German-Style Weizenbock"
}

Response:

204 No Content

DESTROY

DELETE: http://DOMAIN/styles/ID
"http://localhost:3000/styles/2"

Response:

204 No Content
BEERS

INDEX

GET: http://DOMAIN/beers
"http://localhost:3000/beers"

Response:

200 Ok

SHOW

GET: http://DOMAIN/beers/ID
"http://localhost:3000/beers/1"

Response:

200 Ok

CREATE

POST: http://DOMAIN/beers
"http://localhost:3000/beers"
Params: Body, JSON(application/json)
{
  "name": "KBS 2016",
  "style_id": 5,
  "user_id": 1,
  "abv": "11.9%",
  "ibu": "70",
  "nationality": "American",
  "brewery": "Founders",
  "description": "The best Imperial Stout of World"
}

Response:

201 Created

UPDATE

PUT: http://DOMAIN/beers/ID
"http://localhost:3000/beers/1"
Params: Body, JSON(application/json)
{
  "brewery": "Founders Brewing Co"
}

Response:

204 No Content

DESTROY

DELETE: http://DOMAIN/beers/ID
"http://localhost:3000/beers/2"

Response:

204 No Content

Pending Actions

  • Use JSON API format response
  • Build a CRUD web app (with login) that consumes the API
  • Change http basic auth to JWT
  • Deploy on Heroku (both apps: back-end and front-end)

Contributing

My Beers is open source, and we are grateful for [everyone][contributors] who have contributed so far or want to start.