This repository contains a simple Orders API built in Go that utilizes Redis as its primary database. The API is designed to handle basic CRUD operations for orders, and it is implemented using the Chi router.
Before running the application, ensure that you have Go and Redis installed on your system.
-
Clone the repository:
git clone https://github.com/Jakub-Ignatowicz/orders-api-go.git cd orders-api-redis
-
Install dependencies:
go mod download
-
Configure Redis connection: Update the Redis connection details in the
config/config.go
file if needed. -
Run the application:
go run main.go
The API provides the following endpoints for managing orders:
-
List Orders: -
GET /orders
: Retrieve a list of all orders. -
Get Order by ID: -
GET /orders/{id}
: Retrieve details of a specific order by ID. -
Create Order: -
POST /orders
: Create a new order. -
Update Order by ID: -
PUT /orders/{id}
: Update details of a specific order by ID. -
Delete Order by ID: -
DELETE /orders/{id}
: Delete a specific order by ID.
-
curl -X GET https://localhost:8080/orders
-
curl -X GET https://localhost:8080/orders/{id}
-
curl -X POST https://localhost:8080/orders -d '{"name": "Product Name", "price": 19.99, "quantity": 2}'
-
curl -X PUT https://localhost:8080/orders/{id} -d '{"name": "Updated Product Name", "price": 25.99, "quantity": 3}'
-
curl -X DELETE https://localhost:8080/orders/{id}
The application can be configured via the application/config.go
file. Update the Redis connection details, port, or any other necessary configurations.
// application/config.go
package config
type Config struct {
RedisURL string
Port string
}
Feel free to customize the configuration according to your environment.
- github.com/go-chi/chi: Router for the API.
- github.com/go-redis/redis/v8: Redis client for Go.
This project is licensed under the MIT License.
Feel free to contribute, report issues, or suggest improvements. Happy coding!