Resource Helpers
In the previous section, we've learned that a single resource supports multiple HTTP methods/path.
Restful helpers
In the previous section, we've learned that a single resource supports multiple HTTP methods/path.
If you are not planning to use all the HTTP methods, you can the following helper functions to shorten the code.
Interface
func Helper[Input, Output any](
name string,
handler HandlerFn[Input, Output],
metas ...*Meta,
) *ResourceExample
rs := fs.Get("/path", func(c fs.Context, input *Input) (*Output, error) {
return &Output{
Message: "Hello, " + input.Name,
}, nil
})Changes compared to the full version
fs.Getis used instead offs.NewResourceand we don't need to specify the HTTP method in the meta object.- The path is passed as the first argument and is used as the resource name.
Supported helpers
fs.Getfs.Headfs.Postfs.Putfs.Deletefs.Patchfs.Optionsfs.Connectfs.Trace
Resource Meta
The metas parameter is optional, if specified, the first meta object in the list will be used as the resource's metadata.
OpenAPI Spec
The OpenAPI specification is a standard way to describe your API. It includes information about the API's endpoints, request and response schemas, and more.