This project is a Go application that implements a RESTful API for managing recipes and customer orders. It uses the Gin web framework to handle HTTP requests and responses.
-
Recipes Endpoint:
GET /recipes
: Retrieves a list of recipes from arecipes.json
file. Each recipe includes the item name, recipe details, and price.
-
Orders Management:
POST /orders
: Creates a new order by accepting a list of item names and calculates the total price based on the recipes.PUT /orders
: Updates an existing order. (Currently, it functions the same as creating an order.)DELETE /orders/:item
: Deletes a specific item from the order and recalculates the total price.GET /orders
: Retrieves the current order details. (Note: This function may need further implementation as it returns a nil order.)
-
Welcome Message:
GET /
: Returns a welcome message indicating that the Recipes API is active.
-
Prerequisites:
- Install Go (version 1.13 or higher).
- Install the Gin web framework:
go get -u github.com/gin-gonic/gin
-
Setup:
- Ensure you have a
recipes.json
file in the same directory asmain.go
. This file should contain an array ofMenuItem
objects withitem
,recipe
, andprice
fields. Example:[ { "item": "Pizza", "recipe": "Dough, Tomato Sauce, Cheese", "price": 12.99 }, { "item": "Burger", "recipe": "Bun, Patty, Lettuce, Tomato", "price": 9.99 } ]
- Ensure you have a
-
Running the Application:
- Execute the application using:
go run main.go
- The server will start on port
8080
and display:server is running on port 8080...
- Execute the application using:
-
Testing the API:
- Use
curl
, Postman, or any HTTP client to interact with the API endpoints. - Example Requests:
- Get Recipes:
curl http://localhost:8080/recipes
- Create Order:
curl -X POST http://localhost:8080/orders -H "Content-Type: application/json" -d '{"orders":["Pizza","Burger"]}'
- Delete Item from Order:
curl -X DELETE http://localhost:8080/orders/Pizza
- Get Recipes:
- Use
- Go Programming Language: Core language used for application development.
- Gin Web Framework: Used for handling HTTP requests and routing.
- JSON: Data format for input/output, using Go's
encoding/json
package. - File I/O: Reading from
recipes.json
using Go'sio/ioutil
andos
packages.