Go - Api.Route.All()

Register a single handler for all HTTP Methods (GET, POST, PUT, DELETE, PATCH) on the route.

import (
"github.com/nitrictech/go-sdk/nitric"
"github.com/nitrictech/go-sdk/nitric/apis"
)
func main() {
customersRoute := nitric.NewApi("public").NewRoute("/customers")
customersRoute.All(func(ctx *apis.Ctx) {
ctx.Response.Body = []byte("")
})
nitric.Run()
}

Parameters

  • Name
    handler
    Type
    interface{}
    Description

    The callback function to handle all HTTP methods on the given route.

  • Name
    options
    Type
    ...MethodOption
    Description

    Additional options for the route. See below.

Method options

  • Name
    WithNoMethodSecurity()
    Type
    MethodOption
    Description

    Disables security on the method.

  • Name
    WithMethodSecurity()
    Type
    MethodOption
    Description

    Overrides a security rule from API defined JWT rules.

    • Name
      name
      Type
      string
      Description

      The name of the security rule.

    • Name
      scopes
      Type
      []string
      Description

      The scopes of the security rule.

Notes

When using the all() method to register a single function as the handler for all HTTP methods, none of the other methods should be defined on that route.

import (
"github.com/nitrictech/go-sdk/nitric"
"github.com/nitrictech/go-sdk/nitric/apis"
)
func main() {
customersRoute := nitric.NewApi("public").NewRoute("/customers")
customersRoute.All(func(ctx *apis.Ctx) {
/* handle all requests */
})
customersRoute.Get(func(ctx *apis.Ctx) {
/* this handler won't work */
})
nitric.Run()
}
Last updated on Oct 11, 2024