Resource Helpers
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
go
func Helper[Input, Output any](
name string,
handler HandlerFn[Input, Output],
metas ...*Meta,
) *ResourceExample
go
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