This project is an introduction to the concepts of a web API with Go and Gin Web Framework.
The API allows you to create, list, search, update, and delete products. This is a basic project to learn how to set up routes, handle requests and responses, and work with JSON in a Go application.
- Golang installed on your machine
To build the project, use the command:
go build server.gorun the project To run the server, execute the generated file:
./serverBy default, the server will start on port 8000.
List all registered products.
- Request:
localhost:8000/products
Get details of a specific product by ID.
- Request:
localhost:8000/products/1
Search for a product by name.
- Query parameter: product name
- Request:
localhost:8000/products/search?name=book
Create a new product.
- Request:
localhost:8000/products - Request body:
{
"id": 5,
"name": "table",
"price": 125.60
}Update the details of an existing product by ID.
- Request:
localhost:8000/products/1 - Request body:
{
"id": 1,
"name": "pen",
"price": 90.45
}Delete a specific product by ID.
- Request:
localhost:8000/products/2