Categorygithub.com/EstebanHorn/RecipesAPI
modulepackage
0.0.0-20240826005614-1a8fadca054c
Repository: https://github.com/estebanhorn/recipesapi.git
Documentation: pkg.go.dev

# README


Recipes API

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.

Table of Contents

Features

  • 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.

Installation

  1. Clone the repository:

    git clone https://github.com/EstebanHorn/RecipesAPI.git
    cd RecipesAPI
    
  2. Install dependencies:

    go mod tidy
    
  3. Create a .env file in the root directory and add your MongoDB URI:

    MONGOURI=mongodb+srv://yourusername:[email protected]/?retryWrites=true&w=majority
    
  4. Build and run the application:

    go run main.go
    

Configuration

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.

Usage

Once the API is running, you can interact with it using tools like Postman or curl.

Example

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
}'

API Endpoints

MethodEndpointDescription
POST/recipesCreate a new recipe
GET/recipesRetrieve 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

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author