e := echo.New() e.GET("/users", func(c echo.Context) error { id := c.QueryParam("id") name := c.QueryParam("name") // Do something with id and name return c.String(http.StatusOK, "id: "+id+", name: "+name) })
e := echo.New() e.GET("/search", func(c echo.Context) error { query := c.QueryParam("q") // Search for something based on the query param results, err := search(query) if err != nil { return c.String(http.StatusInternalServerError, "Error searching for results") } return c.JSON(http.StatusOK, results) })In this example, we create a new echo instance and define a GET route for "/search". Within the route handler function, we use the c.QueryParam() method to get the value of the "q" query parameter from the URL. We can then use that value to search for something and return the results as a JSON response using the c.JSON() method. If there is an error searching, we return an HTTP 500 status code and an error message using the c.String() method.