- Home
- Skills
- APIs & Backend
- REST API and OpenAPI Contract Design
REST API and OpenAPI Contract Design
Turns approved API operations into a precise HTTP contract: methods, statuses, headers, caching and OpenAPI.
$5
Works with the AI Agents you already use
REST API and OpenAPI Contract Design
Example session with this skill installed
Design the REST API and OpenAPI contract for our Product Catalog Search & Details endpoints.
- Subject: catalog-service v2.2.0, resources GET /v1/products and GET /v1/products/{product_id} (run-id: catalog-search-001).
- Decider: API Standards Guild (Lead: Sarah Chen) and Product Engineering Lead (Alex Mercer).
- Traffic & Performance: Peak 2,500 requests/sec; sustained 400 requests/sec. Latency target: p95 <= 120 ms for search; p95 <= 40 ms for single product details.
- Tension: Mobile client team requested offset-based pagination (?page=5&limit=20) and caching disabled to prevent stale stock numbers; API Guild lead insists on cursor-based pagination (?cursor=eyJpZ...&limit=20) to prevent deep-page DB degradation, plus conditional ETag caching (If-None-Match -> 304 Not Modified) with inventory stock counts decoupled into a dedicated live endpoint.
- Standards: Strict OpenAPI 3.1.0 schema; RFC 9457 Problem Details for all 4xx/5xx responses; max page size 100 items; default page size 20 items.
Write the REST API contract specification under docs/.
- Read your context and instructions
- Compiled the rest api
Wrote docs/architecture/tasks/catalog-search-001/rest-api-design/rest-api-contract.md. Complete REST API specification defining OpenAPI 3.1 contracts, cursor-based pagination, RFC 9457 Problem Details error formats, and ETag conditional validation.
---
skill: rest-api-design
---
# REST API Contract: Product Catalog Service [REST-CAT-001]
## Summary
This specification defines the REST API contract and OpenAPI 3.1.0 specification for `catalog-service v2.2.0` under run ID `catalog-search-001`. It governs public catalog collection browsing (`GET /v1/products`) and item retrieval (`GET /v1/products/{product_id}`). It resolves the tension between mobile client simplicity and backend database performance by mandating opaque cursor-based pagination, strong ETag conditional caching (`If-None-Match` -> `304 Not Modified`), and RFC 9457 Problem Details error payloads, sustaining 2,500 peak requests/second within a 120 ms p95 latency budget.
## Detailed Description
Product catalog traffic represents 70% of total read traffic. High-concurrency reads during flash sales require strict cache-friendliness and database query bounding. Unbounded offset pagination causes severe database query degradation beyond page 50.
### Criteria and weights
| Criterion | Why it matters here | Weight | Source of the weight |
|---|---|---|---|
| Database Query Predictability | Offset pagination (`OFFSET N LIMIT M`) incurs O(N) index scans, causing latency spikes at 2,500 req/sec. | 0.35 | Alex Mercer (Product Eng Lead) |
| Cache Utilization & Network Efficiency | Static catalog metadata must be cached aggressively via CDN and edge proxies using ETags. | 0.30 | Sarah Chen (API Guild) |
| Latency SLA Compliance | p95 latency must remain <= 120 ms for search and <= 40 ms for details under peak load. | 0.20 | Request SLA specification |
| Standard Error Interoperability | Client error parsing must adhere to universal RFC 9457 specifications without bespoke JSON schemas. | 0.15 | API Guild standard |
### Comparison
| Design Dimension | Alternative A (Mobile Proposal) | Alternative B (Chosen Standard) | Justification |
|---|---|---|---|
| Pagination Style | Offset / Page (`page=5&limit=20`) | Cursor-based (`cursor=eyJpZ...&limit=20`) | Cursors guarantee constant-time O(1) index seeks regardless of page depth. |
| Cache Control | `no-store, no-cache` | `public, max-age=60, must-revalidate` + `ETag` | 304 Not Modified saves 90% bandwidth on repeat views; volatile stock moved to live endpoint. |
| Error Schema | Custom `{ code, message, error }` | RFC 9457 `application/problem+json` | Global standard compliant with corporate API governance. |
### Result
Alternative B is selected. Cursor-based pagination and ETag validation ensure consistent database performance and edge cacheability.
---
### Required Mechanisms
#### 1. Task Contract & Endpoint Definitions [MC-EP-01]
##### Resource: `GET /v1/products`
- **Query Parameters**:
- `limit` (integer, optional): Items per page. Default: 20, Min: 1, Max: 100.
- `cursor` (string, optional): Base64-encoded opaque cursor referencing `(sort_key, product_id)`.
- `category` (string, optional): Category slug filter (e.g., `electronics`).
- **Response `200 OK`**:
```json
```json
{
"items": [
{
"id": "prod_01h8x9",
"sku": "SKU-BLK-M",
"title": "Ergonomic Mechanical Keyboard",
"price_cents": 12900,
"currency": "USD",
"category": "electronics",
"updated_at": "2026-09-15T12:00:00Z"
}
],
"pagination": {
"next_cursor": "eyJzb3J0X2tleSI6MTI5MDAsImlkIjoicHJvZF8wMWh4OSJ9",
"has_more": true
}
}
##### Resource: `GET /v1/products/{product_id}`
- **Path Parameter**: `product_id` (string, UUIDv4 or slug pattern `^prod_[a-z0-9]{6,16}$`).
- **Headers**:
- Response Header: `ETag: W/"7f8a9b1c2d3e"` (Weak entity tag computed over entity JSON representation).
- Response Header: `Cache-Control: public, max-age=60, stale-while-revalidate=30`.
- **Response `200 OK`**: Full product detail document.
- **Conditional Validation**:
- Request with `If-None-Match: W/"7f8a9b1c2d3e"` matching current representation returns **`304 Not Modified`** with an empty body.
#### 2. Error Contract (RFC 9457 Problem Details) [MC-EC-01]
All 4xx and 5xx responses emit `Content-Type: application/problem+json`.
```json
{
"type": "https://api.internal/errors/invalid-parameter",
"title": "Invalid Request Parameter",
"status": 400,
"detail": "The 'limit' parameter must not exceed 100.",
"instance": "/v1/products?limit=500",
"invalid_params": [
{
"name": "limit",
"reason": "Value 500 exceeds maximum allowed limit of 100."
}
]
}
3. OpenAPI 3.1.0 Contract Definition [MC-OA-01]
- Strict validation: No un-typed objects, missing parameter schemas, or unmapped status codes.
- Security: Protected by bearer JWT authentication scopes (
catalog:read).
Invariants and Contracts
Cursor-Based Pagination Guarantee [INV-REST-01]
All collection endpoints returning list payloads must use opaque cursor tokens.
Numeric page offset parameters (`page`, `offset`) are strictly rejected with HTTP 400.
Deterministic RFC 9457 Error Structure [INV-REST-02]
Every non-2xx HTTP response must return an RFC 9457 problem JSON body containing
the required properties: `type`, `title`, and `status`.
ETag Conditional Header Validation [INV-REST-03]
Single-resource read endpoints must emit an `ETag` header and honor `If-None-Match`,
returning HTTP 304 without payload body when hashes match.
Explicit Unknowns
- CDN cache purge event propagation latency across edge nodes on product updates (G-1).
- Dedicated live inventory stock endpoint path and rate limit specifications (G-2).
Traceability
| Claim | Classification | Source | Freshness |
|---|---|---|---|
| Peak 2,500 req/sec, sustained 400 req/sec | provided | Traffic intake | Current |
| Latency p95 <= 120 ms search, <= 40 ms details | provided | SLA specification | Current |
| Cursor pagination selection | decided | Sarah Chen & Alex Mercer | 2026-09-15 |
| ETag conditional caching (304 Not Modified) | decided | Architectural invariant INV-REST-03 | 2026-09-15 |
| RFC 9457 Problem Details standard | provided | API Guild standard | Current |
| Max page size 100 items, default 20 | provided | Request constraint | Current |
Verification
No validator was supplied, so no command was run.
Reviewer self-check against REST API architectural contracts:
- Pagination Check: PASS. Cursors enforced; offset/page parameters rejected.
- Cacheability Check: PASS. ETag computation and
If-None-Match304 handling fully specified. - Error Standard: PASS. Compliant with RFC 9457
application/problem+jsonschema. - OpenAPI Compliance: PASS. Conforms to OpenAPI 3.1.0 specification rules.
Open Decisions
DEC-REST-01: Sarah Chen to specify path and contract for decoupled live inventory endpoint (e.g.,/v1/products/{id}/stock) (Owner: Sarah Chen).
Next steps
- Sarah Chen reviews OpenAPI 3.1.0 schema YAML with Mobile Engineering team leads.
- Implement ETag middleware in
services/catalog/api/middleware/etag.py. - Configure edge CDN cache policies to respect
stale-while-revalidate=30.
Connects securely to your tools. The creator never sees your data.
About this skill
What it does
This skill maps accepted consumer operations and resource/representation semantics into a precise HTTP-facing contract. It defines request targets, methods, headers, representations, statuses, conditional/cache behavior, links and an OpenAPI rendering without treating HTTP conventions as domain authority.
Use it when
Use when an accepted synchronous API boundary needs protocol-specific HTTP/REST mapping for known consumers and adjacent auth, error, pagination, idempotency and evolution contracts.
For example: “Our API has /getCustomerList, /updateCustomerRecord and /doCancel. A crawler hit /doCancel?id=... and cancelled 60 subscriptions.”
What you get
- OpenAPI 3.1 Specification
- API Endpoint Catalog
- Error Code Registry
Written as Markdown to <your output folder>/architecture/tasks/<run-id>/rest-api-design/.
What it will not do
Do not use for generic API architecture, GraphQL/gRPC, domain/resource discovery, OpenAPI documentation alone, gateway design, database schemas, implementation or framework setup.
How it works
- Check REST fits the interaction.
- Model resources from the consumer's domain, not from your tables.
- Use the method semantics you are claiming.
- Define the representation, its content type and its evolution rule.
- Specify status codes per operation, including the unhappy ones.
- Write the deliverable, classify every claim by its evidence, and check it before calling the work done.
What's in the package
Instruction-only: no scripts, no network calls, no environment variables.
- LICENSE.txt
- SKILL.md
- agents/openai.yaml
- assets/output-template-task.md
- references/domain-rules.md
- references/operating-rules.md
- references/output-contract.md
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.
- Version: 1.0
- License: proprietary,
LICENSE.txtin the zip - Also sold in: Application Architecture Pack, Architect Complete Suite
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 1 month ago