Custom Headless APIs
Last updated
Was this helpful?
Last updated
Was this helpful?
Custom Headless APIs have two primary use cases:
For a fully headless solution, you will need custom APIs to serve catalogs, categories, and products to your client application.
For any special requirements that are not covered by the out-of-the-box APIs.
The goal is to create endpoints that give you freedom of implementation while respecting our authentication.
Out-of-the-box Headless API available (for example, by using our as a starting point).
Secrets are set up for your stores, and the URI whitelist is correctly configured in the API Access part of the administration interface. You can .
In your project, create a new Class and Inherit from Ucommerce.Web.WebSite.Controllers.HeadlessControllerBase
This will inherit our authentication, restricting its usage to only authenticated clients.
Add a route to your controller. It can match the out-of-the-box route as follows:
In your controller's constructor, you can inject any components you may need in your implementation. For example,
Create and annotate a new method with the HTTP method type and route.
Headless API authentication happens on a per-store basis. You can resolve the StoreId from the claim as follows:
Complete your implementation and return the results to your client.
For reference, here is a full controller example that will return products for a given Category:
For help with return types and choosing the right implementation details,