Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set QueryParams on GET #31

Closed
jgoodall opened this issue Jul 22, 2016 · 7 comments
Closed

How to set QueryParams on GET #31

jgoodall opened this issue Jul 22, 2016 · 7 comments

Comments

@jgoodall
Copy link

I see how to set form and json for POSTs, but how can I set query params on a get request?

@jgoodall
Copy link
Author

To ask a less dumb question - is there a way to do it besides in the GET URL?

@appleboy
Copy link
Owner

@jgoodall

The first way is add Query string in the GET URL. Try the following example:

func TestBasicHelloWorld(t *testing.T) {
  r := gofight.New()

  r.GET("/?a=b&foo=bar").
    // turn on the debug mode.
    SetDebug(true).
    Run(BasicEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {

      assert.Equal(t, "Hello World", r.Body.String())
      assert.Equal(t, http.StatusOK, r.Code)
    })
}

The second way is implement new func SetQuery.

@appleboy
Copy link
Owner

@jgoodall I will implement new func SetQuery.

@jgoodall
Copy link
Author

Yes, putting in URL works fine, just a little unreadable! Thanks, looking forward to the new SetQuery...

@appleboy
Copy link
Owner

@jgoodall Update to v1.0.2 and see the detail information on README.

https://github.com/appleboy/gofight#set-query-string

func TestQueryString(t *testing.T) {
  r := gofight.New()

  r.GET("/hello").
    SetQUERY(gofight.H{
      "a": "1",
      "b": "2",
    }).
    Run(BasicEngine, func(r HTTPResponse, rq HTTPRequest) {
      assert.Equal(t, http.StatusOK, r.Code)
    })
}

@jgoodall
Copy link
Author

Great - thank you. Just noticed that SetQUERY and SetFORM probably should be camel case since they (unlike SetJSON) are not acronyms.

@appleboy
Copy link
Owner

@jgoodall Good Point. I will change it later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants