- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
3.1.3. Create Brand API Route
Create the file src/api/admin/brands/route.ts
with the following content:
This adds a POST
API route at /admin/brands
. In the API route's handler, you execute the createBrandWorkflow
, passing it the request body as input.
You return in the response the created brand.
Test API Route#
To test it out, first, retrieve an authenticated token of your admin user by sending a POST
request to the /auth/user/emailpass
API Route:
Make sure to replace the email and password with your user's credentials.
Then, send a POST
request to /admin/brands
, passing the token received from the previous request in the Authorization
header:
This returns the created brand in the response:
Summary#
By following the previous example chapters, you implemented a custom feature that allows admin users to create a brand by:
- Creating a module that defines and manages the
Brand
data model. - Creating a workflow that uses the module's main service to create a brand record, and implements the compensation logic to delete that brand in case an error occurs.
- Creating an API route that allows admin users to create a brand.
Next Steps#
In the next chapters, you'll learn how to extend data models and associate the brand with a product.