Ruby on Rails 6 course as an API creating a Heroes CRUD.
This repository is part of the Curso de Ruby on Rails 6 como API on YouTube.
Ruby version | 3.0.3 |
Rails version | 6.1.x |
Database | SQLite3 (dev) / PostgreSQL (prod) |
# clone the project
git clone https://github.com/peimelo/curso_tour_of_heroes_api.git
# enter the cloned directory
cd curso_tour_of_heroes_api
# install Ruby on Rails dependencies
bundle install --without production
# create the development and test databases
rails db:create
# create the tables
rails db:migrate
# run the project
rails s
The backend is available at http://localhost:3000
.
To run the tests:
rspec
For all requests, use an Authorization header, of size >= 10 characters, so that you can only manipulate your data, for example:
curl --request GET \
--url 'https://curso-tour-of-heroes-api.herokuapp.com/api/heroes' \
--header 'Authorization: anyTokenCanBeUsed'
The following endpoints are available:
Endpoints | Usage | Params |
---|---|---|
GET /api/heroes |
Get all of the heroes. | |
GET /api/heroes?name=term |
Get all heroes with name like a term . |
term: [String] |
GET /api/heroes/:id |
Get the details of a single hero. | |
POST /api/heroes |
Add a new hero. | name: [String] |
PUT /api/heroes/:id |
Edit the details of an existing hero. | name: [String] |
DELETE /api/heroes/:id |
Remove the hero. |
If you want to import the above requests into Insomnia, use the file Insomnia.json
at the root of this project.
It will be necessary to install the plugin insomnia-plugin-dotenv.
Create an environment variable file at the root of the project to add sensitive data:
touch .env.development
Add the contents below to the file above:
token=anyTokenCanBeUsed
In Insomnia, go to Manage Environments
and set the envFilePath
value to the file path .env.development
:
{
"baseUrl": "http://localhost:3000/api",
"envFilePath": "/path/to/file/your_repo/.env.development"
}
Any .env.*
file is being ignored by this project's GIT.