Skip to content

API & HTTP — REST, Resilience & Caching

Nine packages that form the HTTP infrastructure layer of a Granit application.

Start with the problem you need to solve:

ProblemModuleWhen to use
Clients retry a POST and create duplicatesIdempotencyAny mutation endpoint called by mobile apps or unreliable networks
A single user floods your APIRate LimitingPublic APIs, multi-tenant APIs, any endpoint exposed to untrusted clients
One slow tenant blocks requests for othersBulkheadMulti-tenant SaaS where tenants share compute resources
API responses are large (JSON lists, reports)Response CompressionAny API with responses > 1 KB, especially over mobile networks
You need to push events to external systemsWebhooksIntegration partners expect real-time notifications
You are introducing breaking API changesAPI VersioningAny API with external consumers that cannot upgrade simultaneously
Frontend devs need to explore your APIAPI DocumentationAlways — self-service API exploration reduces support requests
Your API returns inconsistent error shapesException HandlingAlways — standardizes all errors to RFC 7807 Problem Details
Browser clients call your API cross-originCORSAny API consumed by SPAs or third-party frontends
PackagePurpose
CORSDefault policy, ISO 27001 wildcard rejection
API VersioningURL segment versioning, RFC 8594 deprecation headers
API DocumentationScalar OpenAPI UI, OAuth2/PKCE, multi-version docs
Exception HandlingRFC 7807 Problem Details, chain of responsibility mapper
IdempotencyStripe-style middleware, Redis state machine, AES-256 entries
Rate LimitingSlidingWindow, FixedWindow, TokenBucket, Concurrency algorithms
WebhooksHMAC-signed outbound webhooks, retry, subscription management
BulkheadPer-tenant concurrency isolation, feature-based quotas, Wolverine middleware
Response CompressionBrotli + gzip with safe HTTPS defaults, SSE exclusion
graph TD
    CORS[Granit.Http.Cors] --> CO[Granit]
    AV[Granit.Http.ApiVersioning] --> CO
    AD[Granit.Http.ApiDocumentation] --> AV
    AD --> SEC[Granit.Users]
    RC[Granit.ResponseCompression] --> CO
    EH[Granit.Http.ExceptionHandling] --> CO
    ID[Granit.Http.Idempotency] --> CA[Granit.Caching]
    ID --> SEC
    RL[Granit.RateLimiting] --> CO
    RL --> EH
    RL --> FT[Granit.Features]
    RL --> SEC