Test GitHub API with cURL & Postman: Tutorial
In this article
This tutorial shows you how to test GitHub's REST API endpoints using cURL and Postman. You'll learn the essential commands and interface steps to authenticate, make requests, and inspect responses for common tasks like listing repos, viewing user profiles, and creating gists.
Background: Why Test GitHub's API?
GitHub's REST API lets you automate nearly everything you can do on the website: reading repository metadata, managing issues, creating releases, and more. Developers test these endpoints to build integrations, scripts, or simply to understand how the API behaves before writing production code. Using cURL and Postman covers two common workflows: quick terminal checks and a visual, reusable interface for exploring requests and responses.
Prerequisites: What You Need Before You Start
- A GitHub account (free tier works).
- A personal access token (classic) with the appropriate scopes. For public read-only endpoints, you can often skip the token, but authenticated requests have higher rate limits (5,000 requests/hour vs. 60 for unauthenticated).
- cURL installed (comes with macOS and most Linux distributions; on Windows, use the built-in curl.exe in PowerShell or install Git Bash).
- Postman desktop app (free version) installed.
How to Authenticate with GitHub API
The GitHub API accepts authentication via a personal access token (PAT) sent in the Authorization header. The standard format is Authorization: Bearer YOUR_TOKEN (the older token YOUR_TOKEN also works). For example, to see your own profile with cURL:
curl -H "Authorization: Bearer YOUR_TOKEN" https://api.github.com/user
In Postman, add the header manually or use the built-in Bearer Token auth type. Never share your token or commit it to a repository. For testing, you can generate a fine-grained token with limited permissions, but the classic token is simpler for read-only calls.
Testing User Endpoints with cURL
The GitHub API uses predictable URL patterns. For user data, the main endpoints are:
GET /users/{username}– public profile information for any user.GET /user– the authenticated user's profile (requires token).GET /users/{username}/repos– list public repositories for a user.GET /users/{username}/followers– list followers.
Example: fetch the public profile for the user "octocat":
curl https://api.github.com/users/octocat
You'll get JSON with fields like login, name, public_repos, and followers. To list repos, use:
curl https://api.github.com/users/octocat/repos?per_page=5
The per_page parameter limits results (max 100). Add ?sort=updated to order by last update.
Testing User Endpoints with Postman
Postman provides a graphical way to build and save requests. Steps:
- Create a new request (Ctrl+N or Cmd+N).
- Set the method to GET and enter the URL, e.g.,
https://api.github.com/users/octocat. - In the Authorization tab, select "Bearer Token" and paste your token (optional for public data).
- Click Send. The response appears in the lower pane with status code, headers, and body.
- To save the request, click Save and put it in a collection.
Postman also lets you view the response in pretty JSON, copy as cURL (a button under the code icon), and set environment variables for the token and username, which is useful when testing multiple endpoints.
Common Problems and How to Fix Them
- 401 Unauthorized – Your token is missing, invalid, or expired. Check the header spelling and regenerate the token.
- 403 Forbidden – Usually means you hit the rate limit. Check the
X-RateLimit-Remainingresponse header. Add authentication or wait. - 404 Not Found – The user doesn't exist, or the repo is private and you're not authenticated with access.
- JSON parsing errors – If you copy a cURL command from Postman, ensure you include the
--locationflag if there are redirects, and quote the URL properly.
Comparing cURL and Postman for API Testing
cURL is lightweight, scriptable, and great for one-off checks or automation. Postman offers a GUI, history, collections, environment variables, and a test runner – ideal for exploring and documenting. For a quick sanity check, cURL is faster; for building a suite of tests, Postman shines. Many developers use both: cURL in the terminal for debugging, Postman for sharing and reusing requests.
Frequently Asked Questions
Do I need a token to test public user endpoints?
No, but unauthenticated requests are limited to 60 per hour per IP. Adding a token raises that to 5,000 per hour. For serious testing, always use a token.
How do I get a personal access token?
Go to GitHub Settings → Developer settings → Personal access tokens → Tokens (classic). Click "Generate new token", select scopes (for read-only user data, just read:user and public_repo), and copy the token immediately – you won't see it again.
What does the 'X-RateLimit-Remaining' header mean?
It shows how many requests you have left in the current hour window. When it hits zero, you'll get a 403 response. The header X-RateLimit-Reset gives the Unix timestamp when the limit resets.
Can I use Postman to test GraphQL API instead of REST?
Yes, Postman supports GraphQL requests. Set the method to POST, the URL to https://api.github.com/graphql, and put the query in the body. You'll still need an Authorization header with your token.
Why do I get a 304 Not Modified?
GitHub uses conditional requests with ETags. If you send an If-None-Match header with a previous ETag and the data hasn't changed, you get a 304 with no body. This is normal and saves bandwidth.
How do I paginate through many results?
Use the page parameter: ?page=2&per_page=100. The response headers include Link with URLs for the next and last pages. In Postman, you can write a script to loop pages, but for manual testing, just change the page number.