An open API service indexing awesome lists of open source software.

https://github.com/rafaelcamargo/kobbogo-api

An experimental API to dig deeper on Ruby on Rails
https://github.com/rafaelcamargo/kobbogo-api

api-rest jwt-authentication rspec rubocop ruby-on-rails simplecov

Last synced: about 2 months ago
JSON representation

An experimental API to dig deeper on Ruby on Rails

Awesome Lists containing this project

README

        

# Kobbogo API
> An experimental API to dig deeper with Ruby on Rails.

[![CircleCI](https://dl.circleci.com/status-badge/img/gh/rafaelcamargo/kobbogo-api/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/rafaelcamargo/kobbogo-api/tree/master)
[![Coverage Status](https://coveralls.io/repos/github/rafaelcamargo/kobbogo-api/badge.svg?branch=master)](https://coveralls.io/github/rafaelcamargo/kobbogo-api?branch=master)
[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)

## Contributing

1. Install *Ruby 3.x or greater* - Prefer to install Ruby with [Ruby Version Manager](https://rvm.io/).

2. Clone the repo:
``` bash
git [email protected]:rafaelcamargo/kobbogo-api.git
```

3. Go to the project directory
``` bash
cd kobbogo-api
```

4. Install the project dependencies
``` bash
bundle install
```

5. Create and setup databases - *[PostgreSQL](https://www.postgresql.org/) 14.x (server 9.x)* or greater:
``` bash
rails db:create
rails db:migrate
```

6. Serve the API:
``` bash
rails s
```

The API will be running on `http://localhost:3000`.

## Usage

### User Collection

The *User* collection has a single endpoint. The endpoint requires *username* and a *password* to create an user:

| Method | URI | Request Body | Response Status | Response Body |
|--------|--------|--------------|-----------------|---------------|
| **POST** | `/users` | {
  username: String,
  password: String
} | [201](https://www.httpstatuses.org/201) *(Created)* | |

### User Authentication

Authentication has a single endpoint. The endpoint requires user's credentials (*username/password*) and responds with a body containing a *token*, its *expiration date* (i.e. "06-19-2022 21:44"), and *username*:

| Method | URI | Request Body | Response Status | Response Body |
|--------|--------|--------------|-----------------|---------------|
| **POST** | `/auth` | {
  username: String,
  password: String
} | [201](https://www.httpstatuses.org/201) *(Created)* | {
  token: String,
  exp: Date,
  username: String
} |

### Todo Collection

The *Todo* collection has three endpoints. All these endpoints need an Authentication token to be sent via request header. The header key must have the name *Authorization* and its value must be the token returned by the endpoint `/auth`.

#### Create

This endpoint requires a *description* to create a todo.

| Method | URI | Request Body | Response Status | Response Body |
|--------|--------|--------------|-----------------|---------------|
| **POST** | `/todos` | {
  description: String,
} | [201](https://www.httpstatuses.org/201) *(Created)* | {
  id: UUID,
  description: String,
  created_at: Date,
  updated_at: Date,
} |

#### Retrieve

This endpoint does not requires anything.

| Method | URI | Request Body | Response Status | Response Body |
|--------|--------|--------------|-----------------|---------------|
| **GET** | `/todos` | | [200](https://www.httpstatuses.org/200) *(Ok)* | [{
  id: UUID,
  description: String,
  created_at: Date,
  updated_at: Date,
}] |

#### Delete

This endpoint requires a todo id to be passed on the URI.

| Method | URI | Request Body | Response Status | Response Body |
|--------|--------|--------------|-----------------|---------------|
| **DELETE** | `/todos/:id` | | [200](https://www.httpstatuses.org/200) *(Ok)* | |

## Code Format

Ensure that all the code you have added is [properly formatted](https://rubocop.org/):
``` bash
bundle exec rubocop
```

## Tests

Ensure that all the code you have added is covered with [automated tests](https://rspec.info/):
``` bash
bundle exec rspec
```