Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pansani/order-list-api-go-graphql-grpc
https://github.com/pansani/order-list-api-go-graphql-grpc
docker golang graphql grpc
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/pansani/order-list-api-go-graphql-grpc
- Owner: pansani
- Created: 2024-07-30T21:12:05.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-08-07T17:00:15.000Z (3 months ago)
- Last Synced: 2024-09-30T15:41:18.245Z (about 2 months ago)
- Topics: docker, golang, graphql, grpc
- Language: Go
- Homepage:
- Size: 46.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Order Listing Service
This project is an implementation of a simple order listing service using gRPC, GraphQL, and REST API. It demonstrates how to create a multi-service application with a shared PostgreSQL database using Docker Compose.
## Table of Contents
1. [Prerequisites](#prerequisites)
2. [Create .env file](#create-env-file)
3. [Run the Application](#run-the-application)
4. [Run Migrations](#run-migrations)
5. [Insert Sample Data](#insert-sample-data)
6. [Testing the Services](#testing-the-services)
- [REST API](#rest-api)
- [GraphQL](#graphql)
- [gRPC](#grpc)
7. [Clean Up](#clean-up)## 1. Prerequisites
- [Docker](https://www.docker.com/get-started)
- [Docker Compose](https://docs.docker.com/compose/install/)
- [Go](https://golang.org/doc/install)
- [grpcurl](https://github.com/fullstorydev/grpcurl#installation) (for testing gRPC services)## 2. Create .env file
Create a `.env` file in the root directory of the project with the following content:
```ini
DB_USER=user
DB_PASSWORD=password
DB_NAME=orders_db
DB_HOST=db
DB_PORT=5432
```## 3. Run the Application
First, make sure Docker is running, then execute the following commands:
```bash
docker-compose build
docker-compose up -d
```This will build the application and start all the services defined in the `docker-compose.yml` file.
## 4. Run Migrations
Migrations will be automatically run by the migrate service defined in docker-compose.yml.
## 5. Testing the Services
### REST API
You can test the REST API using `curl` or any API testing tool like Postman. The REST API will be available at `http://localhost:8080`.
```bash
curl -X POST -H "Content-Type: application/json" -d '{"user_id": 1, "product_id": 101, "quantity": 2, "status": "pending"}' http://localhost:8080/order
``````bash
curl http://localhost:8080/order
```### GraphQL
You can test the GraphQL API using the GraphQL Playground available at `http://localhost:8081/playground`.
Create Order:
```bash
mutation {
createOrder(user_id: 1, product_id: 101, quantity: 3, status: "pending") {
id
user_id
product_id
quantity
status
created_at
updated_at
}
}
```List Orders:
```bash
query {
listOrders {
id
user_id
product_id
quantity
status
created_at
updated_at
}
}
```### gRPC
You can test the gRPC service using `grpcurl`. The gRPC service will be available at `localhost:50051`.
```bash
grpcurl -plaintext localhost:50051 list
```#### Create Order
```bash
grpcurl -plaintext -d '{
"user_id": 1,
"product_id": 101,
"quantity": 3,
"status": "pending"
}' localhost:50051 order.OrderService/CreateOrder
```#### List Orders
```bash
grpcurl -plaintext -d '{}' localhost:50051 order.OrderService/ListOrders
```## 6. Clean Up
To stop and remove all the containers, network, and volumes, run the following command:
```bash
docker-compose down -v
```