Git Product home page Git Product logo

Comments (7)

julienschmidt avatar julienschmidt commented on May 12, 2024 48

The router matches against the request method and the requested URL path only. ?name=abhijit is the URL query and not part of the URL path.

You can get the query parameter values e.g. this way:

func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
    queryValues := r.URL.Query()
    fmt.Fprintf(w, "hello, %s!\n", queryValues.Get("name"))
}

from httprouter.

julienschmidt avatar julienschmidt commented on May 12, 2024 9

router.GET("/hello", Hello), then use

func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
    queryValues := r.URL.Query()
    fmt.Fprintf(w, "hello, %s!\n", queryValues.Get("name"))
}

The URL query is NOT part of the URL path. The router only matches against the request method and the path.

from httprouter.

b35li avatar b35li commented on May 12, 2024 3

@julienschmidt
How to write the router? the followed code does NOT work??
<code
router.GET("/hello?name=xxx", Hello)

from httprouter.

julienschmidt avatar julienschmidt commented on May 12, 2024 1

@preetamyadav Just must query-escape values first before using them in an URL query. + is used to escape spaces: https://play.golang.org/p/2o1jCP3Ut7

from httprouter.

b35li avatar b35li commented on May 12, 2024

Thanks for quick response. Gratitude.

But after looking through the README and testing, the router should go like this

router.GET("/hello/*filepath", Hello)

then to parse the URL. It works.

from httprouter.

preetamyadav avatar preetamyadav commented on May 12, 2024

http://localhost:8080/api/v1/itineraries/all?auth-token=KeQEtE8VI3duSqXHnrDoFKMeilRfmE&[email protected]

when i tried to get

v := r.URL.Query()

it omittted the + sign from email .

from httprouter.

preetamyadav avatar preetamyadav commented on May 12, 2024

Thanks @julienschmidt

from httprouter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.