Go - Api.Route.Get()

Register a handler for HTTP GET requests to the route.

import (
  "github.com/nitrictech/go-sdk/nitric"
  "github.com/nitrictech/go-sdk/nitric/apis"
)

func main() {
  api := nitric.NewApi("public")

  api.NewRoute("/hello").Get(func(ctx *apis.Ctx) {
    ctx.Response.Body = []byte("Hello World")
  })

  nitric.Run()
}

Parameters

  • Name
    handler
    Required
    Required
    Type
    interface{}
    Description

    The callback function to handle all HTTP request to the given route and method.

  • Name
    options
    Optional
    Optional
    Type
    ...MethodOption
    Description

    Additional options for the route. See below.

Method options

  • Name
    WithNoMethodSecurity()
    Optional
    Optional
    Type
    MethodOption
    Description

    Disables security on the method.

  • Name
    WithMethodSecurity()
    Optional
    Optional
    Type
    MethodOption
    Description

    Overrides a security rule from API defined JWT rules.

    • Name
      name
      Required
      Required
      Type
      string
      Description

      The name of the security rule.

    • Name
      scopes
      Required
      Required
      Type
      []string
      Description

      The scopes of the security rule.