# How to get all query parameters from go *gin.context object?

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683425228368/bbbda42b-0a68-4a47-a97a-2cb65a8e106d.png align="center")

### Introduction:

When working with a web application, it's common to use query parameters to pass data between different parts of the application. In Go, the popular Gin framework provides a *gin.Context object to handle requests and responses. In this article, we will discuss how to get all query parameters from a* gin.Context object in Gin.

### Steps to get all query parameters:

1. First, we need to import the Gin framework package:
    

```go
import "github.com/gin-gonic/gin"
```

1. Create a Gin router and define a route that handles GET requests:
    

```go
router := gin.Default()

router.GET("/path", func(c *gin.Context) {
  // code to get all query parameters goes here
})

router.Run(":8080")
```

1. To get all query parameters from the \*gin.Context object, we can use the c.Request.URL.Query() method:
    

```go
queryParams := c.Request.URL.Query()
```

1. The result of the Query() method is a map\[string\]\[\]string, where the keys are the parameter names and the values are slices of the parameter values. To get the value of a specific parameter, we can use the Get() method:
    

```go
value := queryParams.Get("paramName")
```

1. To loop through all the query parameters, we can use a for loop:
    

```go
for key, values := range queryParams {
  // do something with the key and values
}
```

**Example**:

Let's see an example that demonstrates how to get all query parameters from a \*gin.Context object:

```go
package main

import (
    "fmt"
    "github.com/gin-gonic/gin"
)

func main() {
    router := gin.Default()

    router.GET("/path", func(c *gin.Context) {
        queryParams := c.Request.URL.Query()

        for key, values := range queryParams {
            fmt.Printf("Parameter: %s, Values: %v\n", key, values)
        }

        c.String(200, "Success")
    })

    router.Run(":8080")
}
```

In the above example, we define a route that handles GET requests to the "/path" path. Inside the route function, we get all query parameters using the c.Request.URL.Query() method and loop through them to print their keys and values. Finally, we send a response with a "Success" message.

### Conclusion:

Getting all query parameters from a \*gin.Context object in Gin is a simple and straightforward process using the c.Request.URL.Query() method. With this method, we can easily access and manipulate query parameters in our web applications.

I hope this helps, you!!

**More such articles:**

[https://medium.com/techwasti](Link)

[https://www.youtube.com/channel/UCiTaHm1AYqMS4F4L9zyO7qA](Link)

[https://www.techwasti.com/](Link)

\==========================\*\*=========================

**If this article adds any value to you then please clap and comment.**

**Let’s connect on** [**Stackoverflow**](http://stackoverflow.com/users/3187349/maheshwar-ligade)**,** [**LinkedIn**](https://in.linkedin.com/in/maheshwar-ligade-14447841)**, &** [**Twitter**](https://twitter.com/MaheshwarLigade)**.**
