CoffeeOrders API Server

Build Status License Go Version

Executive Summary

CoffeeOrders is a RESTful API server implemented in Go that provides backend endpoints for “Front-End Web Development: The Big Nerd Ranch Guide” projects. This server serves as a complete backend solution, replicating missing API endpoints from the original educational examples, and enables rapid development setup for frontend applications.

Architecture Overview

The application utilizes the following technologies and patterns: - Language: Go 1.21+ - Architecture: RESTful API with HTTP handlers - Data Storage: In-memory storage (production database integration recommended) - Cross-Platform: Native compilation for Windows, macOS, and Linux - Concurrent Processing: Goroutine-based request handling

Supported Endpoints

Method Endpoint Description
GET /api/coffee-orders Retrieve all coffee orders
POST /api/coffee-orders Create new coffee order
GET /api/coffee-orders/{id} Retrieve specific order
PUT /api/coffee-orders/{id} Update existing order
DELETE /api/coffee-orders/{id} Delete coffee order

Installation Guide

Prerequisites

Binary Installation

Windows (x64)

# Navigate to extracted binary directory
cd coffee-orders-bin
coffeeorders-amd64.exe

macOS (Intel/AMD)

# Navigate to extracted binary directory
cd coffee-orders-bin
chmod +x coffeeorders-amd64-macos
./coffeeorders-amd64-macos

Linux (x64)

# Navigate to extracted binary directory
cd coffee-orders-bin
chmod +x coffeeorders-amd64-linux
./coffeeorders-amd64-linux

Note: ARM64 and ARM32 binaries are available upon request. Please open an issue for specific architecture requirements.

Docker Deployment

Quick Start

# Clone repository
git clone https://github.com/audstanley/coffeeorders-go
cd coffeeorders-go

# Build and run container
docker build -t coffee-orders .
docker run -dp 3001:3001 coffee-orders

Docker Compose

version: '3.8'
services:
  coffee-orders:
    build: .
    ports:
      - "3001:3001"
    environment:
      - NODE_ENV=production

Configuration

The application supports the following configuration options:

Variable Default Description
PORT 3001 HTTP server port
HOST localhost Bind address
LOG_LEVEL info Logging verbosity (debug, info, warn, error)

Environment Variables

export PORT=3001
export HOST=0.0.0.0
export LOG_LEVEL=debug

Usage Examples

API Testing

Install the REST Client extension for VSCode and use the provided .http files in the rest/ directory.

Environment Configuration

Copy rest/.env.example to rest/.env:

baseUrl=http://localhost:3001

Sample API Calls

Create Coffee Order

POST {{baseUrl}}/api/coffee-orders
Content-Type: application/json

{
  "customerName": "John Doe",
  "coffeeType": "Espresso",
  "size": "Large",
  "price": 4.50
}

Get All Orders

GET {{baseUrl}}/api/coffee-orders
Accept: application/json

Development Setup

Local Development

# Clone repository
git clone https://github.com/audstanley/coffeeorders-go
cd coffeeorders-go

# Install dependencies
go mod download
go mod tidy

# Run development server
go run main.go

Building from Source

# Build for current platform
go build -o coffeeorders .

# Cross-compilation
GOOS=linux GOARCH=amd64 go build -o coffeeorders-linux-amd64
GOOS=windows GOARCH=amd64 go build -o coffeeorders-windows-amd64.exe
GOOS=darwin GOARCH=amd64 go build -o coffeeorders-darwin-amd64

Testing

Unit Tests

# Run all tests
go test ./...

# Run tests with coverage
go test -cover ./...

API Testing

Use the provided REST client files in the rest/ directory with VSCode’s REST Client extension to test all endpoints.

Performance Characteristics

Metric Value
Startup Time < 2 seconds
Memory Usage 15-25 MB
Concurrent Requests 1000+
Response Time < 50ms (avg)

Contributing

Contributions are welcome in the following areas: - Database persistence layer (PostgreSQL, MongoDB) - Authentication and authorization middleware - Advanced filtering and search capabilities - Performance optimizations - Unit test coverage improvements

Please submit pull requests with comprehensive test cases and documentation updates.

License

This project is licensed under the MIT License.

Support

For questions, issues, or feature requests: - Create an issue on GitHub - Visit the project documentation


Note: This is an educational project designed to supplement learning materials. For production use, implement proper database persistence and security measures.