Skip to content

Worker API

The Maho Storefront Worker exposes several internal API endpoints for data synchronization, cache management, and client-side operations. These are not public APIs — they're used by the admin module, freshness controller, and internal tooling.

Endpoint Categories

CategoryEndpointsPurpose
SyncPOST /sync, POST /sync/:typePopulate KV from Maho backend
CachePOST /cache/update, POST /cache/purge, POST /cache/deleteManage cached data
FreshnessPOST /freshnessBackground revalidation
ProxyGET /media/*, GET /robots.txt, GET /sitemap.xmlProxy to backend

Authentication

Internal endpoints use a shared secret passed in the request body:

json
{
  "secret": "your-sync-secret"
}

The secret is configured in wrangler.toml as the SYNC_SECRET environment variable.

WARNING

The sync secret is transmitted in the request body, not as a header. Ensure all sync/cache management requests are made over HTTPS.

Client-Side API

The Stimulus controllers use a client-side API wrapper (src/js/api.js) that communicates with the Maho backend through the Worker:

EndpointMethodPurpose
/api/cartGETGet current cart
/api/cart/itemsPOSTAdd item to cart
/api/cart/items/:idPATCHUpdate item quantity
/api/cart/items/:idDELETERemove item from cart
/api/checkout/place-orderPOSTPlace order
/api/auth/loginPOSTCustomer login
/api/customersPOSTCreate account
/api/searchGETSearch products

These endpoints proxy to the Maho REST API with appropriate headers.

Next Steps