This project is a challenge proposed by Rebase, it is an API in Ruby for listing medical exams.
- Ruby
- Sinatra
- Docker
- Redis
- Sidekiq
Only three tools are strictly needed:
- git;
- docker;
- docker-compose.
Now we will need to clone the project, enter the project directory and run the script to prepare the application and start the server, for that follow the steps below.
git clone https://github.com/Jhonny4975/Rebase-challenge.git
cd rebase-challenge
bash run
After waiting for the script to finish its work you should see something like:
Great, that means the server is active (don't close this terminal), now we can proceed with the usage instructions.
To continue we will need an API client, for this example I will use Insomnia.
With the server running, run your client API and make a get request for the http://localhost:3000/tests
route.
It worked out! but why is it empty?
Well, we don't have anything in the database yet, so what we need to do now is create this data. You must be thinking "nice but how do we do that?" well, we have two ways, first, access the container and run a command that reads a previously prepared csv file and persists its data in the database, let's start with that then.
To do this, open another terminal, make sure they are in the same directory as before, and run the following command:
docker-compose run server bash
This command allows us to interact with a terminal inside the container, now we can move on to the next command:
rake db:seed:csv_data_import
After the execution you should see a success message and another one saying that 3900 exams were saved. Now go back to your API client and make the request again.
Wow, it worked, we have a lot of exams now! But what if we want to save our own csv file? This brings us to the second way of populating the database, for which we will need to go back to our API client. You can close the terminal we ran the last command now.
For this step, with the server running, run the client API and make a post request to the http://localhost:3000/import
route, don't forget to upload your csv file before submitting.
If you forget or upload a document that is not a csv, you will see an error like this:
Here is an example request using Insomnia:
Now make a GET request to /tests
again and see the csv data you just sent.
With the server running, run your client API and make a get request for the http://localhost:3000/tests/:token
route.
Example:
If the token is invalid, you will see something like: