URL Path Parameters

Content-Type Requested: *

// Register the route...
app.Get("/{name}/{age:int}/{tail:path}", handler)

func handler(ctx iris.Context) {
    params := ctx.Params()

    name   := params.Get("name")
    age    := params.GetIntDefault("age", 18)
    tail   := strings.Split(params.Get("tail"), "/")
}

Bind

The Context.ReadParams(ptr interface{}) error is the method which binds URL Dynamic Path Parameters from client request to a custom value.

Let's create our Go structure.

type myParams struct {
	Name string   `param:"name"`
	Age  int      `param:"age"`
	Tail []string `param:"tail"`
}

Now, the handler which reads the URL and binds to a "myParams" value.

Request

Result

Last updated

Was this helpful?