Reputation: 51
I am playing around with GitHub API and I am wondering whether there is a way to limit the response size, because I want to return only a few fields instead of calling for the whole JSON.
I know that certain APIs have the possibility of limiting by the query, like adding ?fields=field1, field2, etc, but I am not able to do this for GitHub API.
For instance I would like to get only id, name, and private from https://api.github.com/repos/octokit/octokit.rb.
I am using Jackson and consume via RestTemplate.
--Edit--
My main aim is to limit the time of the response. Using plain GH api it works ~185ms, and I want to achieve at least 50ms. Is that even doable at all?
Upvotes: 2
Views: 2122
Reputation: 174
use the below GraphQL as you wish
first Import the below CURL to POSTMAN
curl -L -X POST 'https://api.github.com/graphql' \
-H 'Authorization: Basic <TOKEN>' \
-H 'Content-Type: application/json' \
--data-raw '{}'
change the Body type to GraphQL
query{
viewer {
name
repositories(last: 10) {
nodes {
name
url
}
}
}
}
Upvotes: 0
Reputation: 316
You can't use the REST api in combination with the graphql library. How must move completely to the graphql library. Calls with the graphql library are totaly different.
Here is german article graphql for beginners: https://www.heise.de/developer/artikel/Java-Anwendungen-mit-GraphQL-Teil-1-4205852.html.
Here is a example query: https://developer.github.com/v4/guides/forming-calls/#example-query So your query should look like this (in http post body): {"query":"{repository(owner:"octokit", name:"octokit.rb"){ id isPrivate name }}"}
Upvotes: 1