Expand description
§StateSet HTTP
HTTP service layer (REST + SSE) for the StateSet embedded commerce engine.
Turns stateset_embedded::Commerce into a real HTTP API powered by
axum, complete with JSON endpoints, pagination, Server-Sent Events,
CORS, request-ID tracing, and structured error responses.
§Quick Start
ⓘ
use stateset_embedded::Commerce;
use stateset_http::ServerBuilder;
use std::net::SocketAddr;
let commerce = Commerce::new(":memory:")?;
let addr: SocketAddr = "0.0.0.0:3000".parse()?;
ServerBuilder::new_from_env(commerce)?
.bind(addr)
.with_cors()
.with_request_id()
.with_bearer_auth("replace-me-with-a-secret")
.serve()
.await?;§Architecture
┌────────────────────────────────────────────────┐
│ HTTP Client │
│ ┌──────────────────────────────────────────┐ │
│ │ axum Router (this crate) │ │
│ │ ┌────────────────────────────────────┐ │ │
│ │ │ stateset-embedded (Commerce) │ │ │
│ │ │ ┌──────────────────────────────┐ │ │ │
│ │ │ │ SQLite / PostgreSQL │ │ │ │
│ │ │ └──────────────────────────────┘ │ │ │
│ │ └────────────────────────────────────┘ │ │
│ └──────────────────────────────────────────┘ │
└────────────────────────────────────────────────┘Re-exports§
pub use routes::api_router;
Modules§
- etag
ETaggeneration and conditional request helpers.- openapi
OpenAPIspecification generation.- routes
- Route modules and router assembly.
Structs§
- Address
Dto - Address DTO shared by orders and customers.
- AppState
- Shared application state injected into every route handler via
axum::extract::State. - Create
Customer Request - Request body for
POST /api/v1/customers. - Create
Invoice Request - Request body for
POST /api/v1/invoices. - Create
Order Item Request - A single line item in a create-order request.
- Create
Order Request - Request body for
POST /api/v1/orders. - Create
Payment Request - Request body for
POST /api/v1/payments. - Create
Product Request - Request body for
POST /api/v1/products. - Create
Refund Request - Request body for
POST /api/v1/payments/:id/refund. - Create
Return Item Request - A single item in a create-return request.
- Create
Return Request - Request body for
POST /api/v1/returns. - Create
Shipment Request - Request body for
POST /api/v1/shipments. - Customer
Filter Params - Query parameters for
GET /api/v1/customerswith filtering. - Customer
List Response - Response body for
GET /api/v1/customers(list). - Customer
Response - Response body for a single customer.
- Event
Stream Params - Query parameters for the SSE event stream endpoint.
- Health
Response - Response body for
GET /health. - Inventory
Adjust Request - Request body for
POST /api/v1/inventory/:sku/adjust. - Inventory
Filter Params - Query parameters for
GET /api/v1/inventorywith filtering. - Inventory
Item Response - Response body for a single inventory item (list view).
- Inventory
List Response - Response body for
GET /api/v1/inventory(list). - Inventory
Response - Response body for inventory stock levels.
- Invoice
Filter Params - Query parameters for
GET /api/v1/invoiceswith filtering. - Invoice
List Response - Response body for
GET /api/v1/invoices(list). - Invoice
Response - Response body for a single invoice.
- IpCidr
- CIDR block used for trusted proxy checks.
- Metrics
Header Limits - Maximum accepted byte lengths for metrics-related forwarding headers.
- Order
Filter Params - Query parameters for
GET /api/v1/orderswith filtering. - Order
Item Response - A single line item in an order response.
- Order
List Response - Response body for
GET /api/v1/orders(list). - Order
Response - Response body for a single order.
- Pagination
Params - Query parameters for paginated list endpoints.
- Payment
Filter Params - Query parameters for
GET /api/v1/paymentswith filtering. - Payment
List Response - Response body for
GET /api/v1/payments(list). - Payment
Response - Response body for a single payment.
- Product
Filter Params - Query parameters for
GET /api/v1/productswith filtering. - Product
List Response - Response body for
GET /api/v1/products(list). - Product
Response - Response body for a single product.
- Ready
Response - Response body for
GET /health/ready. - Record
Invoice Payment Request - Request body for
POST /api/v1/invoices/:id/payments. - Return
Filter Params - Query parameters for
GET /api/v1/returnswith filtering. - Return
List Response - Response body for
GET /api/v1/returns(list). - Return
Response - Response body for a single return.
- Server
Builder - Builder for configuring and launching the HTTP server.
- Shipment
Filter Params - Query parameters for
GET /api/v1/shipmentswith filtering. - Shipment
List Response - Response body for
GET /api/v1/shipments(list). - Shipment
Response - Response body for a single shipment.
- Tenant
Cache Response - Tenant cache status included in health and readiness responses.
- Update
Customer Request - Request body for
PATCH /api/v1/customers/:id. - Update
Product Request - Request body for
PATCH /api/v1/products/:id. - Version
Response - Response body for
GET /version— build & release metadata.
Enums§
- Http
Error - HTTP error wrapper that maps domain errors to appropriate HTTP responses.
Functions§
- decode_
cursor - Decode a keyset cursor into
(sort_key, id). - encode_
cursor - Encode a keyset cursor from
(sort_key, id). - finalize_
page - Trim an overfetched page back to the requested size and return
has_more. - overfetch_
limit - Request one extra row to detect whether another page exists.