This is a RESTful API for managing recipes, allowing users to create, retrieve, update, and delete recipes. The API is built with Go, MongoDB, and the Gorilla Mux router.
- Create new recipes with ingredients, instructions, and preparation time.
- Retrieve existing recipes by ID.
- List all available recipes.
- Update or delete recipes by ID.
- MongoDB as the database for storing recipes.
-
Clone the repository:
git clone https://github.com/EstebanHorn/RecipesAPI.git cd RecipesAPI -
Install dependencies:
go mod tidy
-
Create a
.envfile in the root directory and add your MongoDB URI:MONGOURI=mongodb+srv://yourusername:yourpassword@cluster.mongodb.net/?retryWrites=true&w=majority
-
Build and run the application:
go run main.go
Make sure you have a .env file in the root directory of the project with the following variable:
MONGOURI=mongodb+srv://<username>:<password>@<cluster-url>/<dbname>?retryWrites=true&w=majority
Replace <username>, <password>, <cluster-url>, and <dbname> with your MongoDB credentials and database information.
Once the API is running, you can interact with it using tools like Postman or curl.
To create a new recipe, you can send a POST request to the /recipes endpoint:
curl -X POST http://localhost:8080/recipes -H "Content-Type: application/json" -d '{
"name": "Chocolate Cake",
"ingredients": ["Flour", "Sugar", "Cocoa powder", "Eggs", "Butter", "Milk"],
"instructions": "Preheat the oven to 350°F. Mix the ingredients and bake for 30 minutes.",
"preparationTime": 45
}'| Method | Endpoint | Description |
|---|---|---|
| POST | /recipes |
Create a new recipe |
| GET | /recipes |
Retrieve all recipes |
| GET | /recipes/{id} |
Retrieve a recipe by ID |
| PUT | /recipes/{id} |
Update a recipe by ID |
| DELETE | /recipes/{id} |
Delete a recipe by ID |