This is a challenge to test the Back-End skills using Ruby on Rails.
Challenge reference: Back-End Challenge 20210221
The objective of the challent is to develop a REST API for the FutureSpace Inc company following the requirements proposed.
- Develop a routine to import data from Project: https://ll.thespacedevs.com/2.0.0/launch/
- Develop a REST API with a CRUD
The models must accomplish the Launch fields. Moreover, other two fields are required:
imported_t
: Date field containing the day and hour of the importation;status
: Enum field with the values: draft, trash and published;
Create a Cron job to run the rotine to import data from SpaceDevs API.
The REST API must have the following endpoints:
GET /
: Returns the message "REST Back-end Challenge 20201209 Running"PUT /launchers/:launchId
: Responsible to update a specific launch (launchId
)DELETE /launchers/:launchId
: Remove a launch (launchId
) from the databaseGET /launchers/:launchId
: Get the launch (launchId
) informationGET /launchers
: List all launchers using pagination.
Differential 3 Write a security scheme using API KEY
in the endpoints. Reference
Assuming that you already have ruby installed, if not consult the guide, the next step is to configure the database.
- Create the user
launch_app
withcreatedb
permission. - Set the
LAUNCH_APP_DATABASE_PASSWORD
environment variable with thelaunch_app
user password.
The database credentials are used in the config/database.yml
file.
The required gems are listed in the Gemfile
file. To install them, run the command:
bundle install
Run the command below to create the database:
rails db:create
Then, run the following command to create the database tables and relations:
rails db:migrate
There is a rake task - lib/tasks/launch_import.rake
- to populate the database. Run the command below to execute this task.
rake launch:import_launchs
To access any endpoint of the API, you will need a valid API key. To generate a set of 10 API keys and store them in the database (they are consulted by the application controllers), run the lib/tasks/api_key.rake
task, using the following command:
rake api_key:generate
To run the API, run the rails server:
rails s
First of all, you will need a valid API key, so consult the api_keys
table and get one key to use in the X-API-KEY
header.
- GET
/
curl --location --request GET 'localhost:3000' \ --header 'X-API-KEY: API-KEY-VALUE'
- GET
/launchers
- Without pagination params (returns 25 results)
curl --location --request GET 'localhost:3000/launchers' \ --header 'X-API-KEY: API-KEY-VALUE'
- With pagination params:
curl --location --request GET 'localhost:3000/launchers?page=1&per_page=10' \ --header 'X-API-KEY: API-KEY-VALUE'
- Without pagination params (returns 25 results)
- GET
/launchers/:launchId
curl --location --request GET 'localhost:3000/launchers/e3df2ecd-c239-472f-95e4-2b89b4f75800' \ --header 'X-API-KEY: API-KEY-VALUE'
- PUT
/launchers/:launchId
curl --location --request PUT 'localhost:3000/launchers/e3df2ecd-c239-472f-95e4-2b89b4f75800' \ --header 'X-API-KEY: API-KEY-VALUE' \ --header 'Content-Type: application/json' \ --data-raw '{ "launch": { "name": "another launch", "status": 1, "program": "example program", "mission": { "name": "example mission" }, "pad": { "info_url": "https://ll.thespacedevs.com/2.0.0/launch/" } } }'
- DELETE
/launchers/:launchId
curl --location --request DELETE 'localhost:3000/launchers/48bc7deb-b2e1-46c2-ab63-0ce00fbd192b' \ --header 'X-API-KEY: API-KEY-VALUE'