VividCortex / siesta

Composable framework for writing HTTP handlers in Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to get query parameters ?

cloudtrends opened this issue · comments

hi,

I can run sample examples , such as

http://x.x.x.x/greeting/hello

I want get parameters after ? , such as:

http://x.x.x.x/greetings/?name=hello

Is siesta support this format ?

thanks.

Yes. We support these the same way we support the URL parameters. Take a look at the params example.

I'm going to assume you're expecting a string.

func(c siesta.Context, w http.ResponseWriter, r *http.Request) {
    var params siesta.Params

    // The second argument is the default value for the parameter.
    name := params.String("name", "", "The name of the person to greet")
    if err := params.Parse(r.Form); err != nil {
        // Do something with the error.
        return
    }

    // Do something with *name.
}

hi

@PreetamJinka

Actually , after my test :
first use:

http://localhost:8080/greet/chunfeng

the browser show as my expected: Hello, chunfeng!

But , when I use the url as below format :

http://localhost:8080/greet/?name=chunfeng

The browser show that ,
404 page not found .

Is there somethings I missed ?

thanks.

You would use two routes for that. /greet/:name and /greet.

you are right !

thanks , and I am close this issue now.

No problem! Let us know if you need any more help.