With our types and data store in place, we will now want to expose these in the API.
- Add a Resource definition to the schema
- Update our generator definition
- Add the template for API resources
- Wire resources into the router
We first add a schema for a resource and a CUE ‘function’ for converting models to resources.
Add the following changes in their appropriate places into the existing generator definition.
The following creates CRUD handlers. Note how we can reuse our route handler partial template because we added these in the schema and mapping.
Create a new template called
Some small changes to existing templates as well
Regenerate the Server
You can now run
hof gen ./example and you should find a new
Using the Resources
You could now rebuild and call our CRUD endpoints, except that we haven’t yet implemented the handlers, which we will do in the next section.