This project was build to fulfill a challenge on the Elixir track, from Rocketseat Ignite Course
Techs used:
- Elixir
- Ecto
- Phoenix
- ExMachina
- PostgreSQL
The objective of this challenge was to build a simple CRUD API to monitor and create a meal log.
As said, this API is a simple CRUD, which contains the following endpoints:
- POST
/api/mealsto register new meals on the database- The body passed contains the following parameters:
description: A string containing the meal descriptioncalories: An integer containing the meal caloriesdate: A date in the formatYYYY-MM-DDwhen the meal was consumed
{ "description": "Burguer with fries", "calories": 378, "date": "2022-02-04" }
- The body passed contains the following parameters:
- GET
/api/meals/{id}to list the data of a specific meal- The body of the response contains the following data:
{ "meal": { "meal": { "id": "734ab366-16fe-4c53-a659-c8f6d723fdec", "description": "Burguer with fries", "calories": 378, "date": "2022-02-04" } }, "message": "Meal created!" }
- The body of the response contains the following data:
- DELETE
/api/meals/{id}to delete a specific meal - PUT
/api/meals/{id}to update a specific meal- The bodu of the request can contain the
description,caloriesor/anddate
- The bodu of the request can contain the
Pre-requisites:
- Elixir installed
- Phoenix Framework installed
- PostgreSQL database running
After cloning the repository, please run the following command to install all the project dependencies:
$ mix deps.get
After that, run the following command to set up the database and run the migration
$ mix ecto.setup
And finally run the following command to start the server locally (by default on port 4000)
$ mix phx.server
If everything went well, you can now start sending requests to the endpoints!
You can run the unit tests with the following command:
$ mix test