Skip to content

Latest commit

 

History

History
317 lines (233 loc) · 6.2 KB

API_DOCUMENTATION.md

File metadata and controls

317 lines (233 loc) · 6.2 KB

Order Management System (OMS) API Documentation

Overview

The Order Management System is a microservices application consisting of two main services:

  • Orders Service: Handles order creation and management via HTTP and gRPC APIs
  • Kitchen Service: Provides a web interface for viewing orders

Service Architecture

┌─────────────────┐    gRPC     ┌─────────────────┐
│  Kitchen Service│ ──────────► │  Orders Service │
│  Port: 1000     │             │  HTTP: 8000     │
│  (Web UI)       │             │  gRPC: 9000     │
└─────────────────┘             └─────────────────┘

Orders Service API

Base URL

  • HTTP API: http://localhost:8000
  • gRPC API: localhost:9000

HTTP API Endpoints

Create Order

Creates a new order in the system.

Endpoint: POST /orders

Request Body:

{
  "customer_id": 123,
  "product_id": 456,
  "quantity": 2
}

Request Parameters:

Field Type Required Description
customer_id integer Yes ID of the customer placing the order
product_id integer Yes ID of the product being ordered
quantity integer Yes Number of items to order

Response:

{
  "status": "success"
}

Example Request:

curl -X POST http://localhost:8000/orders \
  -H "Content-Type: application/json" \
  -d '{
    "customer_id": 123,
    "product_id": 456,
    "quantity": 2
  }'

Example Response:

{
  "status": "success"
}

Error Responses:

  • 400 Bad Request: Invalid JSON or missing required fields
  • 500 Internal Server Error: Server error during order creation

gRPC API

Service Definition

The Orders Service implements the following gRPC service:

service OrderService {
  rpc CreateOrder(CreateOrderRequest) returns (CreateOrderResponse);
  rpc GetOrders(GetOrdersRequest) returns (GetOrderResponse);
}

CreateOrder

Creates a new order via gRPC.

Method: OrderService.CreateOrder

Request Message:

message CreateOrderRequest {
  int32 customerID = 1;
  int32 productID = 2;
  int32 quantity = 3;
}

Response Message:

message CreateOrderResponse {
  string status = 1;
}

GetOrders

Retrieves orders for a specific customer.

Method: OrderService.GetOrders

Request Message:

message GetOrdersRequest {
  int32 customerID = 1;
}

Response Message:

message GetOrderResponse {
  repeated Order orders = 1;
}

message Order {
  int32 OrderID = 1;
  int32 CustomerID = 2;
  int32 ProductID = 3;
  int32 Quantity = 4;
}

Kitchen Service API

Base URL

  • Web Interface: http://localhost:1000

Web Interface

The Kitchen Service provides a web-based dashboard for viewing orders.

Endpoint: GET /

Response: HTML page displaying all orders in a table format.

Features:

  • Displays orders in a formatted table
  • Shows Order ID, Customer ID, and Quantity
  • Automatically creates a sample order when accessed
  • Connects to Orders Service via gRPC to fetch data

Example Usage:

# Open in browser
open http://localhost:1000

# Or curl to see HTML
curl http://localhost:1000

Data Models

Order

Represents an order in the system.

{
  "order_id": 42,
  "customer_id": 123,
  "product_id": 456,
  "quantity": 2
}

Fields:

Field Type Description
order_id integer Unique identifier for the order
customer_id integer ID of the customer who placed the order
product_id integer ID of the product being ordered
quantity integer Number of items ordered

Running the Services

Prerequisites

  • Go 1.22.0 or later
  • All dependencies installed (go mod tidy)

Starting the Services

  1. Start Orders Service:

    make run-orders
    # or
    go run services/orders/*.go
  2. Start Kitchen Service:

    make run-kitchen
    # or
    go run services/kitchen/*.go

Service Ports

  • Orders HTTP API: :8000
  • Orders gRPC API: :9000
  • Kitchen Web UI: :1000

Testing the APIs

Test HTTP API

# Create an order
curl -X POST http://localhost:8000/orders \
  -H "Content-Type: application/json" \
  -d '{"customer_id": 123, "product_id": 456, "quantity": 2}'

Test Kitchen Web Interface

# View orders dashboard
curl http://localhost:1000

Test gRPC API

You can use tools like grpcurl or evans to test the gRPC endpoints:

# Install grpcurl
go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest

# List services
grpcurl -plaintext localhost:9000 list

# Call CreateOrder
grpcurl -plaintext -d '{"customerID": 123, "productID": 456, "quantity": 2}' \
  localhost:9000 OrderService.CreateOrder

# Call GetOrders
grpcurl -plaintext -d '{"customerID": 42}' \
  localhost:9000 OrderService.GetOrders

Error Handling

HTTP API Errors

The HTTP API returns standard HTTP status codes:

  • 200 OK: Request successful
  • 400 Bad Request: Invalid request data
  • 500 Internal Server Error: Server error

Error responses include a JSON body with error details.

gRPC API Errors

The gRPC API returns standard gRPC status codes:

  • OK: Request successful
  • INVALID_ARGUMENT: Invalid request parameters
  • INTERNAL: Internal server error

Development Notes

Current Implementation Status

  • ✅ HTTP API for order creation
  • ✅ gRPC API for order creation and retrieval
  • ✅ Web interface for order viewing
  • ✅ In-memory order storage
  • ⚠️ Order IDs are currently hardcoded (42)
  • ⚠️ Limited error handling
  • ⚠️ No authentication/authorization

Future Enhancements

  • Database persistence
  • User authentication
  • Order status tracking
  • Product catalog integration
  • Order history and analytics
  • API versioning
  • Rate limiting
  • Comprehensive error handling

Support

For issues or questions about the API, please refer to the source code or create an issue in the project repository.