API & HTTP — REST, Resilience & Caching
Nine packages that form the HTTP infrastructure layer of a Granit application.
Choosing the right modules
Section titled “Choosing the right modules”Start with the problem you need to solve:
| Problem | Module | When to use |
|---|---|---|
| Clients retry a POST and create duplicates | Idempotency | Any mutation endpoint called by mobile apps or unreliable networks |
| A single user floods your API | Rate Limiting | Public APIs, multi-tenant APIs, any endpoint exposed to untrusted clients |
| One slow tenant blocks requests for others | Bulkhead | Multi-tenant SaaS where tenants share compute resources |
| API responses are large (JSON lists, reports) | HTTP Hosting | Any API with responses > 1 KB, especially over mobile networks |
| You need to push events to external systems | Webhooks | Integration partners expect real-time notifications |
| You are introducing breaking API changes | API Documentation | Any API with external consumers that cannot upgrade simultaneously |
| Frontend devs need to explore your API | API Documentation | Always — self-service API exploration reduces support requests |
| Your API returns inconsistent error shapes | Exception Handling | Always — standardizes all errors to RFC 7807 Problem Details |
| Browser clients call your API cross-origin | HTTP Hosting | Any API consumed by SPAs or third-party frontends |
All packages
Section titled “All packages”| Package | Purpose |
|---|---|
| HTTP Hosting | Auto-registered CORS with ISO 27001 wildcard rejection, Brotli + gzip compression |
| API Documentation | OpenAPI 3.1, URL-segment versioning, RFC 8594 deprecation, Scalar UI (.Scalar companion), OAuth2/PKCE |
| Exception Handling | RFC 7807 Problem Details, chain of responsibility mapper |
| Idempotency | Stripe-style middleware, IIdempotencyStore contract, Redis provider with AES-256-GCM entries |
| Rate Limiting | SlidingWindow, FixedWindow, TokenBucket, Concurrency algorithms |
| Webhooks | HMAC-signed outbound webhooks, retry, subscription management |
| Bulkhead | Per-tenant concurrency isolation, feature-based quotas, Wolverine middleware |
| URL Safety | SSRF-safe outbound URL validation |
Package dependencies
Section titled “Package dependencies”graph TD
HOST[Granit.Http.Hosting] --> CO[Granit]
AD[Granit.Http.ApiDocumentation] --> SEC[Granit.Users]
ADS[Granit.Http.ApiDocumentation.Scalar] --> AD
EH[Granit.Http.ExceptionHandling] --> CO
IDA[Granit.Http.Idempotency.Abstractions] --> CO
ID[Granit.Http.Idempotency] --> IDA
ID --> SEC
IDR[Granit.Http.Idempotency.StackExchangeRedis] --> ID
RL[Granit.RateLimiting] --> CO
RL --> FT[Granit.Features]
HRL[Granit.Http.RateLimiting] --> RL
HRL --> EH
BH[Granit.Bulkhead] --> FT
HBH[Granit.Http.Bulkhead] --> BH
HBH --> EH
The rate-limiting and bulkhead cores are framework-pure — Granit.Http.RateLimiting
and Granit.Http.Bulkhead are the ASP.NET Core bindings (endpoint filter + RFC 7807
mapping), and Granit.RateLimiting.Wolverine / Granit.Bulkhead.Wolverine the message
bindings. See Rate Limiting, Bulkhead and
ADR-062.
See also
Section titled “See also”- Architecture: HTTP Conventions — Status codes, Problem Details, DTO naming
- Security module — JWT Bearer, authorization