GitHub API

Development
Intermediate

Overview

Access GitHub repositories, users, issues, and more

Integration Guide

Step 1: Authentication

The GitHub API allows limited access for unauthenticated requests, but for higher rate limits and access to private data, you'll need to authenticate. There are two main methods:

  1. Personal Access Token (PAT): For personal or testing use. Create one in your GitHub settings.
  2. OAuth App: For production applications that need to access GitHub on behalf of other users. Register an OAuth App.

Step 2: Set Up Your Project

Create the necessary files for your GitHub profile explorer:

  • index.html - The HTML structure
  • styles.css - CSS for styling
  • github.js - JavaScript for API integration

Step 3: Implement the Code

Copy the following code into your project files:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>GitHub Profile Explorer</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <div class="container">
    <h1>GitHub Profile Explorer</h1>
    
    <div class="search-container">
      <input type="text" id="username-input" placeholder="Enter GitHub username">
      <button id="search-btn">Search</button>
    </div>
    
    <div class="profile-container" id="profile-container">
      <!-- Profile data will be displayed here -->
    </div>
    
    <div class="repos-container">
      <h2>Repositories</h2>
      <div class="repo-filters">
        <select id="sort-select">
          <option value="full_name">Name (A-Z)</option>
          <option value="created">Newest</option>
          <option value="updated">Recently Updated</option>
          <option value="pushed">Recently Pushed</option>
        </select>
        <select id="direction-select">
          <option value="asc">Ascending</option>
          <option value="desc">Descending</option>
        </select>
      </div>
      <div id="repos-list">
        <!-- Repositories will be displayed here -->
      </div>
      <div class="pagination" id="pagination">
        <!-- Pagination controls will be displayed here -->
      </div>
    </div>
  </div>
  
  <script src="github.js"></script>
</body>
</html>

Step 4: Test Your Implementation

Open your HTML file in a browser to test your GitHub profile explorer. You should be able to:

  • Search for GitHub users by username
  • View user profile information including avatar, bio, and stats
  • Browse the user's repositories with sorting options
  • Navigate through paginated repository results
  • Click through to view profiles and repositories on GitHub

Error Handling

Common Errors

  • 401 Unauthorized: Invalid or expired token
  • 403 Forbidden: Rate limit exceeded or insufficient permissions
  • 404 Not Found: User or repository doesn't exist
  • 422 Unprocessable Entity: Validation failed or endpoint has been spammed

Rate Limiting

GitHub API has rate limits that vary based on authentication:

  • Unauthenticated requests: 60 requests per hour
  • Authenticated requests: 5,000 requests per hour

You can check your rate limit status by calling: https://api.github.com/rate_limit

API Details

Base URL
https://api.github.com
Authentication
OAuth or Personal Access Token
Documentation
Official Docs

Endpoints

  • GET
    /users/{username}

    Get public information about a GitHub user

    Parameters
    • username*
      string - The GitHub username
  • GET
    /users/{username}/repos

    List public repositories for a user

    Parameters
    • username*
      string - The GitHub username
    • sort
      string - Sort by: created, updated, pushed, full_name (default: full_name)
    • direction
      string - Sort direction: asc or desc (default: asc)
    • per_page
      number - Results per page (max 100, default: 30)
    • page
      number - Page number of results
  • GET
    /repos/{owner}/{repo}

    Get details about a specific repository

    Parameters
    • owner*
      string - The repository owner (username or organization)
    • repo*
      string - The repository name
  • GET
    /repos/{owner}/{repo}/issues

    List issues for a repository

    Parameters
    • owner*
      string - The repository owner (username or organization)
    • repo*
      string - The repository name
    • state
      string - Issue state: open, closed, all (default: open)
    • sort
      string - Sort by: created, updated, comments (default: created)
    • direction
      string - Sort direction: asc or desc (default: desc)
  • GET
    /search/repositories

    Search for repositories

    Parameters
    • q*
      string - Search query
    • sort
      string - Sort by: stars, forks, updated (default: best match)
    • order
      string - Sort order: asc or desc (default: desc)