Curl Github



Dev-related docs
Current status
  • Properly download from github using wget and curl. GitHub Gist: instantly share code, notes, and snippets.
  • Instantly convert curl commands to Java code. This tool turns a curl command into Java Apache HttpClient Fluent code. Currently, it knows the following options: -d/-data, -H/-header, -I/-head, -url, and -X/-request. Feel free to contribute on GitHub! This script derives from Matt Holt's excellent curl-to-Go and curl-to-php.
  • Using curl inside github actions. Ask Question Asked 1 year, 3 months ago. Active 1 year, 3 months ago. Viewed 3k times 6. For one of my CI jobs I need to use a.

Replace user-or-org, repo, and sha1-or-ref accordingly. If you want a zip file instead of a tarball, specify.zip instead of.tar.gz suffix. You can also retrieve the archive of a private repo, by specifying -u token:x-oauth-basic option to curl. Replace token with a personal access token.

Related:
Daily Snaphots
Build Instructions

In the curl project we use git for source code control.

Browse the source repository (on github.com)

The curl sources are kept in a git repository. You can get the most recent curl source files from there at any time. git is the version control system we use for the curl project. All files in the release archive that aren't generated from other files are kept there, to allow full backtracking of older versions. To use git you need a git client, get yours from git-scm.com. Windows users might fancy git for Windows.

This is mostly a feature for you who really want to have a peek in how the current development version looks like, and not if you just want to download a version to run. If you just want to download a tar or binary archive, go here.

If you want to use the git server, run: Note that this will create a curl subdirectory.

If you at a later time want to get the updated set of files, just cd into this directory and run You can also opt to download a daily snapshot.

When you checkout the sources, you get a file named GIT-INFO in the source root that describes how to proceed to compile and build them.

If you are about to do a lot of modifications, discuss it on the curl or libcurl mailing list in advance and please consider to use git directly to do the changes and provide the necessary patches back to the project!

When you do your changes, commit them properly with git using appropriate commit messages and all. Then when you have something to show (and do show us early and often) generate either a pull-request on github or plain old patches and send to the mailing list.

Article version: GitHub.com
Article version: GitHub.com

Learn the foundations for using the REST API, starting with authentication and some endpoint examples.

In this article

Let's walk through core API concepts as we tackle some everyday use cases.

Overview

Most applications will use an existing wrapper library in the languageof your choice, but it's important to familiarize yourself with the underlying APIHTTP methods first.

There's no easier way to kick the tires than through cURL. If you are usingan alternative client, note that you are required to send a validUser Agent header in your request.

Curl

Hello World

Let's start by testing our setup. Open up a command prompt and enter thefollowing command:

The response will be a random selection from our design philosophies.

Next, let's GETChris Wanstrath'sGitHub profile:

Mmmmm, tastes like JSON. Let's add the -i flag to include headers:

There are a few interesting bits in the response headers. As expected, theContent-Type is application/json.

Any headers beginning with X- are custom headers, and are not included in theHTTP spec. For example:

  • X-GitHub-Media-Type has a value of github.v3. This lets us know the media typefor the response. Media types have helped us version our output in API v3. We'lltalk more about that later.
  • Take note of the X-RateLimit-Limit and X-RateLimit-Remaining headers. Thispair of headers indicate how many requests a client can make ina rolling time period (typically an hour) and how many of those requests theclient has already spent.

Authentication

Unauthenticated clients can make 60 requests per hour. To get more requests per hour, we'll need toauthenticate. In fact, doing anything interesting with the GitHub API requiresauthentication.

Using personal access tokens

The easiest and best way to authenticate with the GitHub API is by using Basic Authentication via OAuth tokens. OAuth tokens include personal access tokens.

Use a -u flag to set your username:

When prompted, you can enter your OAuth token, but we recommend you set up a variable for it:

You can use -u 'username:$token' and set up a variable for token to avoid leaving your token in shell history, which should be avoided.

When authenticating, you should see your rate limit bumped to 5,000 requests an hour, as indicated in the X-RateLimit-Limit header. In addition to providing more calls per hour, authentication enables you to read and write private information using the API.

You can easily create a personal access token using your Personal access tokens settings page:

Get your own user profile

When properly authenticated, you can take advantage of the permissionsassociated with your GitHub account. For example, try gettingyour own user profile:

Download

This time, in addition to the same set of public information weretrieved for @defunkt earlier, you should also see the non-public information for your user profile. For example, you'll see a plan object in the response which gives details about the GitHub plan for the account.

Using OAuth tokens for apps

Apps that need to read or write private information using the API on behalf of another user should use OAuth.

OAuth uses tokens. Tokens provide two big features:

  • Revokable access: users can revoke authorization to third party apps at any time
  • Limited access: users can review the specific access that a tokenwill provide before authorizing a third party app

Tokens should be created via a web flow. An applicationsends users to GitHub to log in. GitHub then presents a dialogindicating the name of the app, as well as the level of access the apphas once it's authorized by the user. After a user authorizes access, GitHubredirects the user back to the application:

Treat OAuth tokens like passwords! Don't share them with other users or storethem in insecure places. The tokens in these examples are fake and the names havebeen changed to protect the innocent.

Now that we've got the hang of making authenticated calls, let's move along tothe Repositories API.

Repositories

Almost any meaningful use of the GitHub API will involve some level of Repositoryinformation. We can GET repository details in the same way we fetched userdetails earlier:

In the same way, we can view repositories for the authenticated user:

Or, we can list repositories for another user:

Or, we can list repositories for an organization:

The information returned from these calls will depend on which scopes our token has when we authenticate:

  • A token with public_reposcope returns a response that includes all public repositories we have access to see on github.com.
  • A token with reposcope returns a response that includes all public and private repositories we have access to see on GitHub.

As the docs indicate, these methods take a type parameter thatcan filter the repositories returned based on what type of access the user hasfor the repository. In this way, we can fetch only directly-owned repositories,organization repositories, or repositories the user collaborates on via a team.

In this example, we grab only those repositories that octocat owns, not theones on which she collaborates. Note the quoted URL above. Depending on yourshell setup, cURL sometimes requires a quoted URL or else it ignores thequery string.

Create a repository

Fetching information for existing repositories is a common use case, but theGitHub API supports creating new repositories as well. To create a repository,we need to POST some JSON containing the details and configuration options.

In this minimal example, we create a new private repository for our blog (to be servedon GitHub Pages, perhaps). Though the blog will be public, we've made the repository private. In this single step, we'll also initialize it with a README and a nanoc-flavored .gitignore template.

The resulting repository will be found at https://github.com/<your_username>/blog.To create a repository under an organization for which you'rean owner, just change the API method from /user/repos to /orgs/<org_name>/repos.

Next, let's fetch our newly created repository:

Oh noes! Where did it go? Since we created the repository as private, we needto authenticate in order to see it. If you're a grizzled HTTP user, you mightexpect a 403 instead. Since we don't want to leak information about privaterepositories, the GitHub API returns a 404 in this case, as if to say 'we canneither confirm nor deny the existence of this repository.'

Issues

The UI for Issues on GitHub aims to provide 'just enough' workflow whilestaying out of your way. With the GitHub Issues API, you can pulldata out or create issues from other tools to create a workflow that works foryour team.

Just like github.com, the API provides a few methods to view issues for theauthenticated user. To see all your issues, call GET /issues:

To get only the issues under one of your GitHub organizations, call GET /orgs/<org>/issues:

We can also get all the issues under a single repository:

Pagination

A project the size of Rails has thousands of issues. We'll need to paginate,making multiple API calls to get the data. Let's repeat that last call, thistime taking note of the response headers:

The Link header provides a way for a response to link toexternal resources, in this case additional pages of data. Since our call foundmore than thirty issues (the default page size), the API tells us where we canfind the next page and the last page of results.

Creating an issue

Now that we've seen how to paginate lists of issues, let's create an issue fromthe API.

To create an issue, we need to be authenticated, so we'll pass anOAuth token in the header. Also, we'll pass the title, body, and labels in the JSONbody to the /issues path underneath the repository in which we want to createthe issue:

The response gives us a couple of pointers to the newly created issue, both inthe Location response header and the url field of the JSON response.

Conditional requests

A big part of being a good API citizen is respecting rate limits by caching information that hasn't changed. The API supports conditionalrequests and helps you do the right thing. Consider thefirst call we made to get defunkt's profile:

In addition to the JSON body, take note of the HTTP status code of 200 andthe ETag header.The ETag is a fingerprint of the response. If we pass that on subsequent calls,we can tell the API to give us the resource again, only if it has changed:

The 304 status indicates that the resource hasn't changed since the last timewe asked for it and the response will contain no body. As a bonus, 304 responses don't count against your rate limit.

Woot! Now you know the basics of the GitHub API!

Curl Github Api Examples

  • Basic & OAuth authentication
  • Fetching and creating repositories and issues
  • Conditional requests

Curl Github Zip

Keep learning with the next API guide Basics of Authentication!