order-list-api-go-graphql-grpc

Stars
0
Committers
1

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
  2. Create .env file
  3. Run the Application
  4. Run Migrations
  5. Insert Sample Data
  6. Testing the Services
  7. Clean Up

1. Prerequisites

2. Create .env file

Create a .env file in the root directory of the project with the following content:

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:

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.

curl -X POST -H "Content-Type: application/json" -d '{"user_id": 1, "product_id": 101, "quantity": 2, "status": "pending"}' http://localhost:8080/order
curl http://localhost:8080/order

GraphQL

You can test the GraphQL API using the GraphQL Playground available at http://localhost:8081/playground.

Create Order:

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:

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.

grpcurl -plaintext localhost:50051 list

Create Order

grpcurl -plaintext -d '{
  "user_id": 1,
  "product_id": 101,
  "quantity": 3,
  "status": "pending"
}' localhost:50051 order.OrderService/CreateOrder

List Orders

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:

docker-compose down -v
Related Projects