Browse Source

Merge pull request #305 from JustinBeckwith/patch-1

add querystring parameter example to readme
Manu Mtz.-Almeida 10 years ago
parent
commit
5680762712
1 changed files with 18 additions and 0 deletions
  1. 18 0
      README.md

+ 18 - 0
README.md

@@ -140,6 +140,24 @@ func main() {
 	r.Run(":8080")
 }
 ```
+
+#### Querystring parameters
+```go
+func main() {
+    router := gin.Default()
+
+    // Query string parameters are parsed using the existing underlying request object.  
+    // The request responds to a url matching:  /welcome?firstname=Jane&lastname=Doe
+    router.GET("/welcome", func(c *gin.Context) {
+        firstname := c.DefaultQuery("firstname", "Guest")
+        lastname := c.Query("lastname") // shortcut for c.Request.URL.Query().Get("lastname")
+
+        c.String(http.StatusOK, "Hello %s %s", firstname, lastname)
+    })
+    router.Run(":8080")
+}
+```
+
 ###Form parameters
 ```go
 func main() {