Coder Social home page Coder Social logo

RESTClient not accepting query string about go-gh HOT 4 CLOSED

cli avatar cli commented on June 27, 2024
RESTClient not accepting query string

from go-gh.

Comments (4)

gennaro-tedesco avatar gennaro-tedesco commented on June 27, 2024 1

Thank you very much for your exhaustive reply, it works fine!

from go-gh.

mislav avatar mislav commented on June 27, 2024

You can add query parameters to the "search/repositories" string by constructing a url.Values object and serializing it to string using its Encode() method.

The argument to client.Get(path) is the path component of the URL with optional query parameters separated with ?.

from go-gh.

gennaro-tedesco avatar gennaro-tedesco commented on June 27, 2024

Thank you for your quick reply. However, when you say:

The argument to client.Get(path) is the path component of the URL with optional query parameters separated with ?.

would this mean that at the end of the day one must pass a whole string of the form

search/repositories?name=<name>?language=lang

to client.Get()? Because this looks different from what the query string for gh API /search/repositories -f q='...' is (so it is a little hard to understand what the right grammar is).

from go-gh.

mislav avatar mislav commented on June 27, 2024

When you do

gh api -X GET search/repositories -f q1=foo -f q2=bar

that's equivalent to

gh api search/repositories?q1=foo&q2=bar

with the added bonus that you don't have to worry about encoding all the special characters in the query string properly, since that's handled by gh api.

Similarly, you could do:

client.Get("path?q1=foo&q2=bar")

and that will work, but I wouldn't recommend it because, again, you'd have to worry about properly encoding query values. Instead, you should do:

searchTerm := "<name>"
repoLanguage := "go"
myQuery := url.Values{}
myQuery.Add("q", fmt.Sprintf("%s in:name language:%s", searchTerm, repoLanguage))
myQuery.Add("per_page", "30")
client.Get("path?"+myQuery.Encode())

from go-gh.

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.