Skip to content

5. REST API Implementation #6

@mrserverless

Description

@mrserverless
  • 5.1 Create rest/errors.go
    • Define error response structure (code, message, details)
    • Error constants (NOT_FOUND, INVALID_INPUT, INTERNAL_ERROR)
    • Error response helpers (JSON formatting)
  • 5.2 Implement rest/middleware.go
    • Request logging middleware (request ID, method, path, duration)
    • Error recovery middleware (panic handling)
    • CORS middleware (configurable origins)
    • Content-Type validation middleware (require application/json for POST/PUT)
  • 5.3 Implement rest/handlers.go - Account handlers
    • GET /accounts/{id} → AccountService.RetrieveCurrentAccount
    • GET /accounts/{id}/balance → AccountService.RetrieveCurrentAccountBalance
    • Input validation (ID not empty)
    • Error handling (not found, internal errors)
    • JSON response formatting
  • 5.4 Implement rest/handlers.go - Transaction handlers
    • GET /transactions/{id} → TransactionService.RetrievePaymentTransaction
    • GET /accounts/{id}/transactions → TransactionService.RetrievePaymentTransactionHistory
    • Query parameter parsing (fromDate, toDate, limit, offset)
    • Input validation (date range, pagination parameters)
    • Error handling and JSON response
  • 5.5 Implement rest/handlers.go - Consent handlers
    • GET /consents/{id} → ConsentService.RetrieveConsent
    • GET /consents/{id}/status → ConsentService.RetrieveConsentStatus
    • Input validation and error handling
    • JSON response formatting
  • 5.6 Implement rest/server.go
    • NewRESTServer(services...) function
    • Configure http.ServeMux with all routes
    • Apply middleware stack
    • Health check endpoint (GET /health)
    • Export handler for embedding in unified server
  • 5.7 Write unit tests for REST handlers
    • Test each endpoint with mock domain services
    • Test error cases (not found, invalid input)
    • Test query parameter parsing
    • Test error response formatting

Source: openspec/changes/bootstrap-mvp-foundation/tasks.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions