20 — REST API Standards

Status: Ratified Version: 1.0.0 Applies to: hunterx/api, OpenAPI schema, clients, webhooks


1. Purpose

The REST API exposes the platform programmatically and is the basis for integrations, CI/CD, and the future GUI. It follows REST conventions, OpenAPI 3.1, and async job semantics for long operations.


2. API Versioning


3. Authentication

Four modes (configurable per deployment):

  1. API keysAuthorization: Bearer <key>; keys are scoped (resource + engagement) and revocable.
  2. OAuth2 / OIDC — bearer JWT; RBAC claims; audience pinned.
  3. mTLS — client certificates for machine-to-machine.
  4. Local username/password — argon2id hashed; session cookies (HTTP-only, SameSite).

4. Schemas


5. Common Response Envelope

Standard list/object responses:

{
  "data": { ... },
  "meta": { "correlation_id": "...", "requested_at": "...", "duration_ms": 12 }
}

List responses additionally:

{
  "data": [ ... ],
  "pagination": {
    "page": 1, "page_size": 50,
    "total": 123, "total_pages": 3,
    "next": "/api/v1/findings?page=2&page_size=50",
    "previous": null
  }
}

6. Async Job Model

Long operations (mission start, report generation, tool sync, exports):

POST /api/v1/missions            → 202 Accepted
Location: /api/v1/jobs/{job_id}

GET /api/v1/jobs/{job_id}
{
  "data": {
    "job_id": "...", "status": "running|succeeded|failed|cancelled",
    "progress": 0.42,
    "result_ref": "/api/v1/missions/{id}",
    "error": null | { "code": "...", "message": "..." }
  }
}

7. Pagination


8. Filtering & Sorting


9. Errors

Uniform error envelope:

{
  "error": {
    "code": "HX-SCOPE-001",
    "message": "Target outside engagement scope",
    "details": { ... },
    "retryable": false,
    "correlation_id": "..."
  }
}
Status Meaning
400 Malformed request / validation
401 Unauthenticated
403 Forbidden (RBAC/scope)
404 Not found
409 Conflict (duplicate, state conflict)
422 Schema validation failed (details list)
429 Rate limited (Retry-After)
500 Internal (safe message, no stack)
503 Unavailable (degradation; Retry-After)

10. Rate Limiting


11. Security Headers & Controls


12. Idempotency & Concurrency


13. Webhooks


14. Health & Observability


15. API Design Conventions


16. OpenAPI & Client Generation


17. References