Hutch/API_REFERENCE.md

b2f3bce0c254e11c4a7e871c3bb844a09c53a96e
hutch/Hutch/API_REFERENCE.md rendered · source · history · blame · raw

146 lines · 3780 bytes

Sourcehut API Reference

This document provides context and references for working with SourceHut's APIs.

Official Documentation

The official SourceHut API documentation can be found at:

Services and Their APIs

git.sr.ht (Git Repositories)

todo.sr.ht (Ticket Tracking)

hg.sr.ht (Mercurial Repositories)

lists.sr.ht (Mailing Lists)

builds.sr.ht (CI/CD)

meta.sr.ht (User Accounts)

Authentication

All API requests require a Personal Access Token with the appropriate scopes.

GraphQL Conventions

Common Types

# Cursor-based pagination
type Query {
  items(cursor: Cursor, filter: Filter): ItemsPage
}

type ItemsPage {
  results: [Item!]!
  cursor: Cursor
}

# Filter structure (varies by service)
input Filter {
  search: String
  # ... other service-specific filters
}

Error Handling

SourceHut APIs return GraphQL errors in the following format:
{
  "data": null,
  "errors": [
    {
      "message": "Error message",
      "path": ["query", "field"],
      "extensions": {
        "code": "ERROR_CODE"
      }
    }
  ]
}

Rate Limiting

  • Rate limits: Vary by service and authentication status
  • Headers: Check X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset
  • Unauthenticated: Lower limits (typically 60 requests/hour)
  • Authenticated: Higher limits (typically 5000 requests/hour)

Development Notes

API Exploration

Use GraphiQL interfaces available at each service's /graphql endpoint to:

  • Explore the schema
  • Test queries
  • Understand available fields and types

Common Issues

  1. Filtering: Some services may not support all filter operations. Check the schema.
  2. Pagination: Always handle cursor properly for pagination.
  3. Caching: SourceHut APIs may have aggressive caching. Use cache headers appropriately.

Example Query Structure

query {
  repositories(cursor: $cursor, filter: $filter) {
    results {
      id
      name
      description
      # ... other fields
    }
    cursor
  }
}

# Variables
{
  "filter": {
    "search": "query string"
  }
}

Troubleshooting

  1. 401 Unauthorized: Check token scopes and expiration
  2. 403 Forbidden: Verify you have access to the requested resource
  3. 429 Too Many Requests: Implement proper rate limiting in your client
  4. 500 Internal Server Error: Check if the API is temporarily down

Additional Resources