GitHub Profile Next.js API with Octokit
This Gist contains a Next.js API route implemented in TypeScript for interacting with the GitHub API using the Octokit library. The primary purpose of this API route is to retrieve information about repositories belonging to a specific GitHub user.
Features:
- Endpoint: The API exposes an endpoint at
/api/reposfor handling HTTP GET requests. - Parameter: Expects a
usernameparameter in the query string to identify the target GitHub user. Example usage:http://localhost:3000/api/repos?username=sametcn99. - Error Handling: Includes robust error handling for scenarios such as missing parameters or failed GitHub API requests.
- GitHub Authentication: Utilizes a GitHub token obtained from environment variables (
process.env.GH_TOKEN) for authentication.
Usage:
- Make a GET request to the API route, providing the target GitHub user's username as a parameter.
- Ensure the availability of environment variables, especially the GitHub token (
GH_TOKEN), for successful authentication.
Dependencies:
Important Notes:
- This script showcases best practices for handling GitHub API requests in a Next.js environment.
- Customize the user agent (
userAgent) for proper identification in GitHub API requests.
How to Integrate:
- Copy the provided TypeScript code into your Next.js project's API routes.
- Install the necessary dependencies using your package manager (
npm installoryarn install). - Set up environment variables, especially the GitHub token (
GH_TOKEN), for authentication.
Feel free to use and modify this script according to your project requirements. It serves as a foundation for building GitHub-related functionality into your Next.js application.