- Ruby >= 2.5.1
- PostgreSQL 10.4
brew update
brew install postgres
gem install bundler
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib postgresql-server-dev-all cmake
gem install bundler
bundle install
cp config/database.example.yml config/database.yml
echo "POSTGRESQL_PASSWORD='YourPassword'" >> .env
echo "POSTGRESQL_USERNAME='YourUserName'" >> .env
bin/rails db:setup
bin/rails db:migrate
bin/rails db:seed
We use rspec framework to test our rails api:
bundle exec rspec
Run the local server api at http://localhost:3000 with:
bin/rails s
bundle exec rails generate model ModelName column_name1:column_type1 column_name1:column_type1 ... column_name1:column_type1
see rails generate
Do correct associations.
Write that were created by the rails generate.
- write factories
- use shoulda-matchers to test validators.
We are on v1, when create a new end-point create with api::v1::
.
bundle exec rails generate scaffold_controller api::v1::name
This makes the code look like this:
module Api
module V1
class NameController < ApplicationController
...
end
end
end
Add resources to routes.rb
file:
namespace 'api' do
namespace 'v1' do
...
resources :yor_controller_name
...
end
end
Write the tests in the files that were created by the rails generate.
- test controller
- test requests
- test routing
see rails generate
- index
List all trails
that current_user
has association
do
http GET http://www.your_domain/api/v1/trails
returns
[
{
"created_at": "2018-09-17T04:53:30.281Z",
"description": "Frankly, my dear, I don’t give a damn.",
"duration": 3,
"id": 35,
"updated_at": "2018-09-17T04:53:30.281Z"
},
{
"created_at": "2018-09-17T04:53:30.525Z",
"description": "You talking to me?",
"duration": 4,
"id": 36,
"updated_at": "2018-09-17T04:53:30.525Z"
}
]
- show
Get informations of one trail
that current_user
has association
do
http GET http://www.your_domain/api/v1/trails/4
returns
{
"created_at": "2018-09-17T04:53:30.281Z",
"description": "Frankly, my dear, I don’t give a damn.",
"duration": 3,
"id": 35,
"updated_at": "2018-09-17T04:53:30.281Z"
}
-
create [WIP] (will be used by professional profiles)
-
update [WIP] (will be used by professional profiles)
-
delete [WIP] (will be used by professional profiles)
- index
List all activities
that current_user
and trial:id
has association
do
http GET http://www.your_domain/api/v1/trails/1/activities
returns
[
{
"created_at": "2018-09-17T04:53:30.281Z",
"description":"this is a description",
"id":2,
"title":"this title is cool",
"updated_at": "2018-09-17T04:53:30.281Z"
},
{
"created_at": "2018-09-17T04:53:30.281Z",
"description":"this is another description",
"id":15,
"title":"this tile isn't cool",
"updated_at": "2018-09-17T04:53:30.281Z"
}
]
- index
-
index [WIP] (will be used by professional profiles)
-
show [WIP] (will be used by professional profiles)
-
create [WIP] (will be used by professional profiles)
-
update [WIP] (will be used by professional profiles)
-
delete [WIP] (will be used by professional profiles)
[WIP]