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/*Proxy media files to backend
AgentsGET /llms.txt, GET /robots.txt, GET /sitemap.xml, GET /.well-known/*Agent-readiness surface (storefront-generated, not proxied)

Extending Maho API Resources ​

PHP modules can enrich API responses (categories, products, store config) without touching core files using the extensions map pattern. See Extending Resources.

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 ​