hub-api(1)
π hub-api(1) β the low-level GitHub API request interface, bestie β¨
okay so first things first: this is from the hub manual, and it's literally the page that teaches you how to talk directly to the GitHub API like a total main character. no cap, it's giving "I know what I'm doing" energy. let's get into it π«Ά
πΈ SYNOPSIS πΈ
hub api [-it] [-X METHOD] [-H HEADER] [--cache TTL] ENDPOINT [-F
FIELD|--input FILE]
that's the whole vibe check right there. now let's break it down β¨
π OPTIONS π
-X,--method METHODβ the HTTP method you wanna use for the request, default is"GET". but lowkey it's automatic: the method switches to"POST"if you use--field,--raw-field, or--input. and if you wanna force fields into the query string for a GET request instead of the JSON body of a POST, use-XGET. periodt π-F,--field KEY=VALUEβ data to serialize with the request. here's where it gets iconic:VALUEhas some magic handling, so if you want to send arbitrary string values, use--raw-fieldinstead.- if
VALUEstarts with"@", the rest of that value is interpreted as a filename to read from. use"@-"to read from standard input. - if
VALUEis"true","false","null", or looks like a number, an appropriate JSON type is used instead of a string. slay. - it is not possible to serialize
VALUEas a nested JSON array or hash. instead, construct the request payload externally and pass it via--input. iykyk.
- if
unless -XGET was used, all fields are sent serialized as JSON within the request body. when ENDPOINT is "graphql", all fields other than "query" are grouped under "variables". see β¨https://graphql.org/learn/queries/#variablesβ© β¨
-f,--raw-field KEY=VALUEβ same as--field, except it allows values starting with"@", literal strings"true","false", and"null", as well as strings that look like numbers. no magic, just raw vibes π¦--input FILEβ the filename to read the raw request body from. use"-"to read from standard input. use this when you wanna manually construct the request payload. you're the main character, you build it yourself π-H,--header KEY:VALUEβ set an HTTP request header. simple, clean, iconic.-i,--includeβ include HTTP response headers in the output. so you can see everything the server is saying, not just the body π-t,--flatβ parse response JSON and output the data in a line-based key-value format suitable for use in shell scripts. literally perfect for when you need things to just work in a script π--paginateβ automatically request and output the next page of results until all resources have been listed. for GET requests, this follows the<next>resource as indicated in the"Link"response header. for GraphQL queries, this utilizespageInfothat must be present in the query; see EXAMPLES.
note that multiple JSON documents will be output as a result. if the API rate limit has been reached, the final document that is output will be the HTTP 403 notice, and the process will exit with a non-zero status. one way this can be avoided is by enabling --obey-ratelimit. π
--color[=WHEN]β enable colored output even if stdout is not a terminal.WHENcan be one of"always"(default for--color),"never", or"auto"(default). give your terminal the aesthetic it deserves π πΈ--cache TTLβ cache valid responses to GET requests forTTLseconds. when using"graphql"asENDPOINT, caching will apply to responses to POST requests as well. just make sure to not use--cachefor any GraphQL mutations. not me warning you about mutations caching, that would be a disaster π--obey-ratelimitβ after exceeding the API rate limit, pause the process until the reset time of the current rate limit window and retry the request. note that this may cause the process to hang for a long time (maximum of 1 hour). like, literally an hour. go touch grass while you wait π±ENDPOINTβ the GitHub API endpoint to send the HTTP request to. default is"/".- to learn about available endpoints, see β¨https://developer.github.com/v3/β©. to make GraphQL queries, use
"graphql"asENDPOINTand pass-F query=QUERY. - if the literal strings
"{owner}"or"{repo}"appear inENDPOINTor in the GraphQL"query"field, fill in those placeholders with values read from the git remote configuration of the current git repository. so smart, lowkey genius π§
- to learn about available endpoints, see β¨https://developer.github.com/v3/β©. to make GraphQL queries, use
π₯ EXAMPLES π₯
okay bestie, here are the actual examples, verbatim, no cap:
# fetch information about the currently authenticated user as JSON
$ hub api user
# list user repositories as line-based output
$ hub api --flat users/octocat/repos
# post a comment to issue #23 of the current repository
$ hub api repos/{owner}/{repo}/issues/23/comments --raw-field Β΄body=Nice job!Β΄
# perform a GraphQL query read from a file
$ hub api graphql -F query=@path/to/myquery.graphql
# perform pagination with GraphQL
$ hub api --paginate graphql -f query=Β΄
query($endCursor: String) {
repositoryOwner(login: "USER") {
repositories(first: 100, after: $endCursor) {
nodes {
nameWithOwner
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
Β΄
those are literally the moves. use them wisely, queen πβ¨
π SEE ALSO π
hub(1)β the main hub page, obviously. go read it if you haven't, bestie π«Ά
and that's the whole page! this was hub version 2.14.2, dated 07 Jan 2024, so you know it's fresh-ish. now go forth and make those API calls with main character energy π β¨πΈ
π¦ where this page comes from
- opensuse-leap 16.0: hub 2.14.2-bp160.1.13 Β· MIT
- opensuse-leap 16.0: hub 2.14.2-bp160.1.13 Β· MIT
- opensuse-leap 16.0: hub 2.14.2-bp160.1.13 Β· MIT
- opensuse-leap 16.0: hub 2.14.2-bp160.1.13 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms