[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6D1N3D96DA86T2B6BKGN4BY":3,"skill-same:01M6D1N3D96DA86T2B6BKGN4BY":66},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":38,"linkOnly":39,"markdownContent":40,"markdownBody":41,"frontMatter":42,"refName":43,"commitSha":44,"skillDirectory":45,"forksCount":46,"repositoryHtmlUrl":47,"repositoryHomepageUrl":48,"ownerHtmlUrl":49,"ownerBlogUrl":48,"ownerDescription":50,"updatedAt":51,"install":52,"resources":65},"01M6D1N3D96DA86T2B6BKGN4BY","backend-api",null,"Designing an HTTP API and its contract: routes and methods, status codes, validating input, response shapes, pagination, filtering, sorting and sparse fields, bulk and long-running operations, conditional requests, idempotency keys, rate limit headers, versioning and deprecation, OpenAPI, API keys or OAuth for third parties, content negotiation, CORS, uploads. Read before adding or changing endpoints.","enowdev\u002Fenowxcli","enowdev","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F179420349?v=4","01M6D1MVX2KC0X3Z9NESE7P22K","Enow Dev.","01M6D1MW1FMZGBDKWAJY4GQX81",67,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fbackend-api\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37],"backend api","api","backend","read","contract","methods","pagination","endpoints","uploads","operations","filtering","status","versioning","cors","openapi","OAuth","negotiation","content","http","2026-11-10 10:12:30",false,"---\nname: backend-api\ndescription: \"Designing an HTTP API and its contract: routes and methods, status codes, validating input, response shapes, pagination, filtering, sorting and sparse fields, bulk and long-running operations, conditional requests, idempotency keys, rate limit headers, versioning and deprecation, OpenAPI, API keys or OAuth for third parties, content negotiation, CORS, uploads. Read before adding or changing endpoints.\"\n---\n\n# The API and its contract\n\nThe generated API has verbs in its paths, `200` with an error inside, lists\nwith no limit, a create that runs twice on a retry, and a field renamed\nunder the same version. One part of the backend; the whole is in `backend`.\nFollow the project's existing style first (REST, RPC, GraphQL, tRPC, server\nactions); these rules are for REST over JSON and carry over where they fit.\n\n## 1. Routes\n\n- Resources as plural nouns, the action in the method: `GET \u002Forders`,\n  `POST \u002Forders`, `GET \u002Forders\u002F{id}`, `PATCH \u002Forders\u002F{id}`,\n  `DELETE \u002Forders\u002F{id}`. Not `\u002FgetOrders` or `\u002Forders\u002Fcreate`.\n- One level of nesting where the child belongs to the parent\n  (`\u002Forders\u002F{id}\u002Fitems`); deeper than that, give the child its own route.\n- An action that is not create, read, update or delete becomes a sub-resource\n  named as a noun or a verb on the record: `POST \u002Forders\u002F{id}\u002Frefunds`,\n  `POST \u002Forders\u002F{id}\u002Fcancel`.\n- One case everywhere, the project's: `kebab-case` paths, and `camelCase` or\n  `snake_case` fields, never mixed.\n- `\u002Fme` for the caller's own things (`GET \u002Fme\u002Forders`). Nothing private in a\n  path or query string (emails, tokens): URLs land in logs and history.\n\n## 2. Methods and status codes\n\n| Situation | Status |\n|---|---|\n| Read, or update that returns the record | `200` |\n| Created | `201`, with the record and a `Location` header |\n| Accepted for later (a job was queued) | `202`, with where to check |\n| Done, nothing to return | `204` |\n| Malformed or invalid input | `400` (or `422` if the project uses it for validation) |\n| Not signed in, or the token is bad | `401` |\n| Signed in but not allowed | `403`; `404` when even revealing the record exists would leak |\n| No such record | `404` |\n| A method the path does not take | `405`, with an `Allow` header |\n| Conflicts with the current state (a duplicate, already paid, stale version) | `409` |\n| `If-Match` no longer matches; `If-Match` required but missing | `412`; `428` |\n| Body over the size limit; a content type the endpoint does not take | `413`; `415` |\n| Too many requests | `429`, with `Retry-After` |\n| Our fault | `500`; `503` when a dependency is down |\n\n`GET` never changes anything. `PUT` replaces the whole record, `PATCH`\nchanges the fields sent; most edits are `PATCH`, with merge semantics\n(RFC 7396): a field left out stays as it is, `null` clears it.\n\n## 3. Input\n\n- Validate every input at the boundary with the project's schema library\n  (zod or valibot, pydantic, a Form Request, serde with validation): body,\n  query string, path parameters and headers you read.\n- Refuse unknown fields, or strip them, but never pass the parsed body to the\n  database as it is: copy the fields a caller may set, so nobody sets\n  `role`, `price` or `ownerId` by adding them to the JSON (mass assignment).\n- Types and limits in the schema: required or not, string lengths, number\n  ranges, formats (email, URL, UUID), array sizes. A request body over a set\n  size (1 MB for JSON unless the feature needs more) is refused before it is\n  parsed.\n- Trim strings; normalise what compares (emails lowercased); parse dates as\n  ISO 8601 with a time zone and ids in their real type. Bodies arrive as\n  `application\u002Fjson` or get `415`; one that does not parse is a `400`\n  (`malformed_json`), never a `500`.\n- Report every field that failed in one response, with a stable code per\n  field, so a form can mark all of them at once (the format is in\n  `backend-errors`).\n\n## 4. Responses\n\n- One shape everywhere. A record is returned as itself\n  (`{ \"id\": \"ord_…\", \"status\": \"paid\", ... }`); a list as\n  `{ \"items\": [...], \"nextCursor\": \"…\" }` (or with `total` when paging by\n  number). Keep the project's shape if it already has one.\n- Ids as strings. Times as ISO 8601 in UTC (`2026-09-29T10:15:00Z`). Money as\n  an integer in the smallest unit with its currency\n  (`{ \"amount\": 1500000, \"currency\": \"IDR\" }`), never a float. Enums as\n  lowercase strings, documented as a list that can grow.\n- Return only the fields the caller may see: build the response from a\n  schema or a resource class, never by serialising the database row (it\n  leaks password hashes, internal flags and future columns).\n- `null` for a known empty value; leave a field out only when the contract\n  says it is optional. A create or update returns the record as saved.\n\n## 5. Lists\n\n- Every list is paginated in the query: `?limit=` (default 25, maximum 100)\n  and `?cursor=` for long or growing lists, or `?page=` with a `total` when\n  the caller jumps to a page. The cursor is opaque (an encoded sort key and\n  id), and the order is stable (the sort column, then the id). A `total` is\n  a count on every page: offer it with page numbers, not on large tables.\n- Filters as named parameters in the schema: `?status=paid,refunded` (OR\n  within a field, AND across fields), ranges as a half-open pair\n  (`?createdFrom=2026-09-01T00:00:00Z&createdTo=2026-10-01T00:00:00Z`, from\n  inclusive, to exclusive), search as `?q=`. Keep a bracket style\n  (`?total[gte]=1000`) where the project already has one.\n- Sort as `?sort=-createdAt,name`: a list, `-` for descending, allowed\n  fields only, the id added as the last key so pages never repeat or skip.\n- Unknown filter or sort fields are a `400`, not ignored, and never pasted\n  into SQL. Search with a minimum length and the same limit.\n- Sparse fields (`?fields=id,status`) only for large records; related\n  records with `?expand=customer` from an allowed list, one level deep,\n  loaded in one query. Small APIs need neither.\n\n## 6. Bulk endpoints\n\n- Hundreds of writes in one call: `POST \u002Fproducts\u002Fbatch` with\n  `{ \"items\": [...] }`, a documented maximum (100 to 1000), `413` past it,\n  and an idempotency key.\n- All or nothing by default: one transaction, and a failure lists each bad\n  item by index (`items[3].sku`). When items are independent and the client\n  can retry the failures, answer `200` with a result per item, in order\n  (`{ \"results\": [{ \"index\": 1, \"status\": 409, \"code\": \"sku_taken\" }] }`).\n- Deletes as `POST \u002Forders\u002Fbatch-delete` with the ids (a body on `DELETE`\n  is dropped by some proxies). Past a few thousand rows it is an import: an\n  upload and a job (section 7).\n\n## 7. Long-running operations\n\nWork that takes more than a few seconds (an export, an import, a report)\nanswers at once with a status resource:\n\n```http\nPOST \u002Fexports              202 Accepted, Location: \u002Fexports\u002Fexp_31\nGET  \u002Fexports\u002Fexp_31       200 { \"id\": \"exp_31\", \"status\": \"running\", \"progress\": 40 }\nGET  \u002Fexports\u002Fexp_31       200 { \"id\": \"exp_31\", \"status\": \"succeeded\", \"resultUrl\": \"…\" }\n```\n\n- States `queued`, `running`, `succeeded`, `failed` (with a problem object),\n  `cancelled`; `Retry-After: 3` on the status response paces the polling.\n- The result is a resource or a signed URL (`backend-files`); cancel with\n  `POST \u002Fexports\u002F{id}\u002Fcancel`; the status is kept for days. Webhooks or SSE\n  (`backend-realtime`) can tell the client sooner; polling always works.\n\n## 8. Writes that must happen once\n\n- A create that must not repeat (an order, a payment, a message sent) takes\n  an `Idempotency-Key` header: the first response is stored with the key for\n  24 hours and returned again for the same key. The client makes one key (a\n  UUID) per operation and resends it only when retrying that operation.\n\n```sql\nCREATE TABLE idempotency_keys (\n  caller_id    bigint      NOT NULL,\n  key          text        NOT NULL CHECK (length(key) \u003C= 255),\n  request_hash text        NOT NULL,\n  status       smallint,              -- null while the first request runs\n  response     jsonb,                 -- body and the headers that matter\n  created_at   timestamptz NOT NULL DEFAULT now(),\n  PRIMARY KEY (caller_id, key)\n);\n```\n\n- Same key and request (hash of method, path and body), finished: replay\n  the stored status, `Location` and body exactly, with\n  `Idempotent-Replayed: true`. Still running: `409` with `Retry-After: 1`.\n  Different request: `422`. Missing where required: `400`. A `400` for bad\n  input is not stored, so the fixed request can reuse the key; rows past 24\n  hours are deleted by a scheduled job.\n- Work that stays in your database inserts the key in the same transaction:\n  a rollback removes both, and the retry runs fresh. Work that calls a\n  provider commits the key first (so a concurrent retry sees `409`) and\n  passes a key derived from it (`\u003Ckey>:charge`) to the provider's own\n  idempotency, so a crash between the call and the save is safe to retry.\n\n## 9. Edits that two people can make at once\n\n- The record carries a `version` (`backend-data`), returned in the body and\n  as a strong `ETag` (`\"7\"`); a weak one (`W\u002F\"7\"`) never matches `If-Match`.\n- The update sends it back, one way per API: `If-Match: \"7\"` (`412` when\n  stale, `428` when required but missing), or `version` in the body (`409`,\n  `stale_version`). The SQL update is conditional\n  (`WHERE id = $1 AND version = $2`), not a check before it; the client\n  shows the current record rather than overwriting it.\n- `If-None-Match` on a `GET` with the `ETag` gets `304` (`backend-caching`).\n\n## 10. Rate limit headers\n\nEvery `429` carries `Retry-After` in seconds. The quota left goes in the\nIETF draft fields or the `X-RateLimit-Limit`, `-Remaining`, `-Reset` trio\n(one, documented, exposed through CORS). Limits per key or user, stricter\nper IP when anonymous (`backend-security`).\n\n```http\nHTTP\u002F1.1 429 Too Many Requests\nRetry-After: 30\nRateLimit-Policy: \"default\";q=100;w=60\nRateLimit: \"default\";r=0;t=30\n```\n\n## 11. Change, versions and deprecation\n\n- Adding a field or an endpoint is safe. Renaming, removing or changing a\n  field's meaning breaks callers: add the new one, keep the old until\n  callers have moved, then remove it. A public API carries a version\n  (`\u002Fv1\u002F...`). Also breaking: a new required input, a changed type, format\n  or default, tighter validation, another status or error code.\n\n| Strategy | Example | Use |\n|---|---|---|\n| Path | `\u002Fv1\u002Forders` | The default for public APIs: visible in logs, easy to route and test; never `?version=` |\n| Date-pinned header | `Api-Version: 2026-09-01`, pinned per account | A large public API changing often; needs a layer translating old shapes |\n| Media type | `Accept: application\u002Fvnd.example.v2+json` | Rarely: invisible in URLs and awkward with curl |\n| None | Your own frontend is the only client | Expand and contract, server deployed first |\n\n- On its way out, it says so on every response (`Deprecation`, RFC 9745;\n  `Sunset`, RFC 8594); usage per caller is watched, callers are told, and\n  it goes after the date (6 to 12 months for a public API):\n\n```http\nDeprecation: @1788220800\nSunset: Tue, 01 Jun 2027 00:00:00 GMT\nLink: \u003Chttps:\u002F\u002Fexample.com\u002Fdocs\u002Fmigrate-to-v2>; rel=\"deprecation\"\n```\n\n## 12. OpenAPI as the contract\n\n- Describe the API where it cannot drift: OpenAPI generated from the schemas\n  (zod-to-openapi, FastAPI's own, Scribe or Scramble for Laravel,\n  `@fastify\u002Fswagger`, springdoc-openapi, ASP.NET Core's, utoipa, huma), or\n  the shared types module for a client in the same repository; spec first\n  (oapi-codegen, openapi-typescript) when it is agreed before the code.\n- OpenAPI 3.1: each operation with an `operationId`, schemas, the problem\n  responses, the security scheme and an example; served at `\u002Fopenapi.json`\n  and rendered in the docs (`docs-api`). In CI, lint it, fail on breaking\n  changes against the main branch, and fuzz the running API against it:\n\n```sh\nnpx @redocly\u002Fcli lint openapi.json\noasdiff breaking base-openapi.json openapi.json --fail-on ERR\nschemathesis run http:\u002F\u002Flocalhost:3000\u002Fopenapi.json\n```\n\n## 13. Around the endpoints\n\n- Third parties: a developer's server acting for its own account uses an\n  API key in `Authorization: Bearer sk_live_…`, never the query string\n  (`backend-auth`); an app acting for your users uses OAuth 2 (code flow,\n  PKCE, scopes named for actions such as `orders:read`, revocable grants),\n  never a pasted password or key. Events go out as signed webhooks\n  (`backend-integrations`).\n- JSON in and out; errors as `application\u002Fproblem+json`; an `Accept` you\n  cannot produce gets `406`, or JSON anyway if the project does that.\n- gzip or Brotli for responses over about 1 KB (at the proxy or CDN when\n  there is one), with `Vary: Accept-Encoding`; not for images or archives.\n- CORS lists the origins that may call; never `*` together with cookies or\n  credentials. The origin is matched exactly against config and echoed with\n  `Vary: Origin`; `Access-Control-Max-Age: 7200` (Chromium's cap; without it\n  a preflight is cached 5 seconds and precedes nearly every call);\n  `Access-Control-Expose-Headers` for what the client reads (`Location`,\n  `ETag`, `Retry-After`, `X-Request-Id`, the rate limit fields).\n- Uploads: a size limit, the type checked from the content rather than the\n  extension, a generated name, storage outside the web root (object storage\n  and signed URLs when large), never executed or served with the uploaded\n  type unchecked (`backend-files`).\n- Rate limits on sign-in, sign-up, password reset, anything that sends email\n  or costs money (`backend-security`).\n\n## Check it\n\n- `curl -si` each new endpoint: the status, `Location` on a create, the\n  problem body on a failure; `?limit=1000` clamped, `?sort=passwordHash` 400.\n- The same create sent twice with one `Idempotency-Key` makes one record and\n  replays the same body; a `PATCH` with an old `If-Match` gets `412`.\n- A preflight (`curl -si -X OPTIONS` with `Origin` and\n  `Access-Control-Request-Method`) shows the origin and max age; the OpenAPI\n  lint and breaking-change diff pass, or the break is in the report.\n\n## Avoid\n\nVerbs in paths; `200` with an error inside; a body written to the database\nas parsed; a database row as the response; floats for money; dates without a\nzone; a list with no limit; sort or filter fields concatenated into SQL; a\ncreate that runs twice when the client retries; a weak `ETag` for\n`If-Match`; personal data in URLs; a breaking change shipped under the same\nversion; an endpoint removed without `Sunset` and a date.\n","# The API and its contract\n\nThe generated API has verbs in its paths, `200` with an error inside, lists\nwith no limit, a create that runs twice on a retry, and a field renamed\nunder the same version. One part of the backend; the whole is in `backend`.\nFollow the project's existing style first (REST, RPC, GraphQL, tRPC, server\nactions); these rules are for REST over JSON and carry over where they fit.\n\n## 1. Routes\n\n- Resources as plural nouns, the action in the method: `GET \u002Forders`,\n  `POST \u002Forders`, `GET \u002Forders\u002F{id}`, `PATCH \u002Forders\u002F{id}`,\n  `DELETE \u002Forders\u002F{id}`. Not `\u002FgetOrders` or `\u002Forders\u002Fcreate`.\n- One level of nesting where the child belongs to the parent\n  (`\u002Forders\u002F{id}\u002Fitems`); deeper than that, give the child its own route.\n- An action that is not create, read, update or delete becomes a sub-resource\n  named as a noun or a verb on the record: `POST \u002Forders\u002F{id}\u002Frefunds`,\n  `POST \u002Forders\u002F{id}\u002Fcancel`.\n- One case everywhere, the project's: `kebab-case` paths, and `camelCase` or\n  `snake_case` fields, never mixed.\n- `\u002Fme` for the caller's own things (`GET \u002Fme\u002Forders`). Nothing private in a\n  path or query string (emails, tokens): URLs land in logs and history.\n\n## 2. Methods and status codes\n\n| Situation | Status |\n|---|---|\n| Read, or update that returns the record | `200` |\n| Created | `201`, with the record and a `Location` header |\n| Accepted for later (a job was queued) | `202`, with where to check |\n| Done, nothing to return | `204` |\n| Malformed or invalid input | `400` (or `422` if the project uses it for validation) |\n| Not signed in, or the token is bad | `401` |\n| Signed in but not allowed | `403`; `404` when even revealing the record exists would leak |\n| No such record | `404` |\n| A method the path does not take | `405`, with an `Allow` header |\n| Conflicts with the current state (a duplicate, already paid, stale version) | `409` |\n| `If-Match` no longer matches; `If-Match` required but missing | `412`; `428` |\n| Body over the size limit; a content type the endpoint does not take | `413`; `415` |\n| Too many requests | `429`, with `Retry-After` |\n| Our fault | `500`; `503` when a dependency is down |\n\n`GET` never changes anything. `PUT` replaces the whole record, `PATCH`\nchanges the fields sent; most edits are `PATCH`, with merge semantics\n(RFC 7396): a field left out stays as it is, `null` clears it.\n\n## 3. Input\n\n- Validate every input at the boundary with the project's schema library\n  (zod or valibot, pydantic, a Form Request, serde with validation): body,\n  query string, path parameters and headers you read.\n- Refuse unknown fields, or strip them, but never pass the parsed body to the\n  database as it is: copy the fields a caller may set, so nobody sets\n  `role`, `price` or `ownerId` by adding them to the JSON (mass assignment).\n- Types and limits in the schema: required or not, string lengths, number\n  ranges, formats (email, URL, UUID), array sizes. A request body over a set\n  size (1 MB for JSON unless the feature needs more) is refused before it is\n  parsed.\n- Trim strings; normalise what compares (emails lowercased); parse dates as\n  ISO 8601 with a time zone and ids in their real type. Bodies arrive as\n  `application\u002Fjson` or get `415`; one that does not parse is a `400`\n  (`malformed_json`), never a `500`.\n- Report every field that failed in one response, with a stable code per\n  field, so a form can mark all of them at once (the format is in\n  `backend-errors`).\n\n## 4. Responses\n\n- One shape everywhere. A record is returned as itself\n  (`{ \"id\": \"ord_…\", \"status\": \"paid\", ... }`); a list as\n  `{ \"items\": [...], \"nextCursor\": \"…\" }` (or with `total` when paging by\n  number). Keep the project's shape if it already has one.\n- Ids as strings. Times as ISO 8601 in UTC (`2026-09-29T10:15:00Z`). Money as\n  an integer in the smallest unit with its currency\n  (`{ \"amount\": 1500000, \"currency\": \"IDR\" }`), never a float. Enums as\n  lowercase strings, documented as a list that can grow.\n- Return only the fields the caller may see: build the response from a\n  schema or a resource class, never by serialising the database row (it\n  leaks password hashes, internal flags and future columns).\n- `null` for a known empty value; leave a field out only when the contract\n  says it is optional. A create or update returns the record as saved.\n\n## 5. Lists\n\n- Every list is paginated in the query: `?limit=` (default 25, maximum 100)\n  and `?cursor=` for long or growing lists, or `?page=` with a `total` when\n  the caller jumps to a page. The cursor is opaque (an encoded sort key and\n  id), and the order is stable (the sort column, then the id). A `total` is\n  a count on every page: offer it with page numbers, not on large tables.\n- Filters as named parameters in the schema: `?status=paid,refunded` (OR\n  within a field, AND across fields), ranges as a half-open pair\n  (`?createdFrom=2026-09-01T00:00:00Z&createdTo=2026-10-01T00:00:00Z`, from\n  inclusive, to exclusive), search as `?q=`. Keep a bracket style\n  (`?total[gte]=1000`) where the project already has one.\n- Sort as `?sort=-createdAt,name`: a list, `-` for descending, allowed\n  fields only, the id added as the last key so pages never repeat or skip.\n- Unknown filter or sort fields are a `400`, not ignored, and never pasted\n  into SQL. Search with a minimum length and the same limit.\n- Sparse fields (`?fields=id,status`) only for large records; related\n  records with `?expand=customer` from an allowed list, one level deep,\n  loaded in one query. Small APIs need neither.\n\n## 6. Bulk endpoints\n\n- Hundreds of writes in one call: `POST \u002Fproducts\u002Fbatch` with\n  `{ \"items\": [...] }`, a documented maximum (100 to 1000), `413` past it,\n  and an idempotency key.\n- All or nothing by default: one transaction, and a failure lists each bad\n  item by index (`items[3].sku`). When items are independent and the client\n  can retry the failures, answer `200` with a result per item, in order\n  (`{ \"results\": [{ \"index\": 1, \"status\": 409, \"code\": \"sku_taken\" }] }`).\n- Deletes as `POST \u002Forders\u002Fbatch-delete` with the ids (a body on `DELETE`\n  is dropped by some proxies). Past a few thousand rows it is an import: an\n  upload and a job (section 7).\n\n## 7. Long-running operations\n\nWork that takes more than a few seconds (an export, an import, a report)\nanswers at once with a status resource:\n\n```http\nPOST \u002Fexports              202 Accepted, Location: \u002Fexports\u002Fexp_31\nGET  \u002Fexports\u002Fexp_31       200 { \"id\": \"exp_31\", \"status\": \"running\", \"progress\": 40 }\nGET  \u002Fexports\u002Fexp_31       200 { \"id\": \"exp_31\", \"status\": \"succeeded\", \"resultUrl\": \"…\" }\n```\n\n- States `queued`, `running`, `succeeded`, `failed` (with a problem object),\n  `cancelled`; `Retry-After: 3` on the status response paces the polling.\n- The result is a resource or a signed URL (`backend-files`); cancel with\n  `POST \u002Fexports\u002F{id}\u002Fcancel`; the status is kept for days. Webhooks or SSE\n  (`backend-realtime`) can tell the client sooner; polling always works.\n\n## 8. Writes that must happen once\n\n- A create that must not repeat (an order, a payment, a message sent) takes\n  an `Idempotency-Key` header: the first response is stored with the key for\n  24 hours and returned again for the same key. The client makes one key (a\n  UUID) per operation and resends it only when retrying that operation.\n\n```sql\nCREATE TABLE idempotency_keys (\n  caller_id    bigint      NOT NULL,\n  key          text        NOT NULL CHECK (length(key) \u003C= 255),\n  request_hash text        NOT NULL,\n  status       smallint,              -- null while the first request runs\n  response     jsonb,                 -- body and the headers that matter\n  created_at   timestamptz NOT NULL DEFAULT now(),\n  PRIMARY KEY (caller_id, key)\n);\n```\n\n- Same key and request (hash of method, path and body), finished: replay\n  the stored status, `Location` and body exactly, with\n  `Idempotent-Replayed: true`. Still running: `409` with `Retry-After: 1`.\n  Different request: `422`. Missing where required: `400`. A `400` for bad\n  input is not stored, so the fixed request can reuse the key; rows past 24\n  hours are deleted by a scheduled job.\n- Work that stays in your database inserts the key in the same transaction:\n  a rollback removes both, and the retry runs fresh. Work that calls a\n  provider commits the key first (so a concurrent retry sees `409`) and\n  passes a key derived from it (`\u003Ckey>:charge`) to the provider's own\n  idempotency, so a crash between the call and the save is safe to retry.\n\n## 9. Edits that two people can make at once\n\n- The record carries a `version` (`backend-data`), returned in the body and\n  as a strong `ETag` (`\"7\"`); a weak one (`W\u002F\"7\"`) never matches `If-Match`.\n- The update sends it back, one way per API: `If-Match: \"7\"` (`412` when\n  stale, `428` when required but missing), or `version` in the body (`409`,\n  `stale_version`). The SQL update is conditional\n  (`WHERE id = $1 AND version = $2`), not a check before it; the client\n  shows the current record rather than overwriting it.\n- `If-None-Match` on a `GET` with the `ETag` gets `304` (`backend-caching`).\n\n## 10. Rate limit headers\n\nEvery `429` carries `Retry-After` in seconds. The quota left goes in the\nIETF draft fields or the `X-RateLimit-Limit`, `-Remaining`, `-Reset` trio\n(one, documented, exposed through CORS). Limits per key or user, stricter\nper IP when anonymous (`backend-security`).\n\n```http\nHTTP\u002F1.1 429 Too Many Requests\nRetry-After: 30\nRateLimit-Policy: \"default\";q=100;w=60\nRateLimit: \"default\";r=0;t=30\n```\n\n## 11. Change, versions and deprecation\n\n- Adding a field or an endpoint is safe. Renaming, removing or changing a\n  field's meaning breaks callers: add the new one, keep the old until\n  callers have moved, then remove it. A public API carries a version\n  (`\u002Fv1\u002F...`). Also breaking: a new required input, a changed type, format\n  or default, tighter validation, another status or error code.\n\n| Strategy | Example | Use |\n|---|---|---|\n| Path | `\u002Fv1\u002Forders` | The default for public APIs: visible in logs, easy to route and test; never `?version=` |\n| Date-pinned header | `Api-Version: 2026-09-01`, pinned per account | A large public API changing often; needs a layer translating old shapes |\n| Media type | `Accept: application\u002Fvnd.example.v2+json` | Rarely: invisible in URLs and awkward with curl |\n| None | Your own frontend is the only client | Expand and contract, server deployed first |\n\n- On its way out, it says so on every response (`Deprecation`, RFC 9745;\n  `Sunset`, RFC 8594); usage per caller is watched, callers are told, and\n  it goes after the date (6 to 12 months for a public API):\n\n```http\nDeprecation: @1788220800\nSunset: Tue, 01 Jun 2027 00:00:00 GMT\nLink: \u003Chttps:\u002F\u002Fexample.com\u002Fdocs\u002Fmigrate-to-v2>; rel=\"deprecation\"\n```\n\n## 12. OpenAPI as the contract\n\n- Describe the API where it cannot drift: OpenAPI generated from the schemas\n  (zod-to-openapi, FastAPI's own, Scribe or Scramble for Laravel,\n  `@fastify\u002Fswagger`, springdoc-openapi, ASP.NET Core's, utoipa, huma), or\n  the shared types module for a client in the same repository; spec first\n  (oapi-codegen, openapi-typescript) when it is agreed before the code.\n- OpenAPI 3.1: each operation with an `operationId`, schemas, the problem\n  responses, the security scheme and an example; served at `\u002Fopenapi.json`\n  and rendered in the docs (`docs-api`). In CI, lint it, fail on breaking\n  changes against the main branch, and fuzz the running API against it:\n\n```sh\nnpx @redocly\u002Fcli lint openapi.json\noasdiff breaking base-openapi.json openapi.json --fail-on ERR\nschemathesis run http:\u002F\u002Flocalhost:3000\u002Fopenapi.json\n```\n\n## 13. Around the endpoints\n\n- Third parties: a developer's server acting for its own account uses an\n  API key in `Authorization: Bearer sk_live_…`, never the query string\n  (`backend-auth`); an app acting for your users uses OAuth 2 (code flow,\n  PKCE, scopes named for actions such as `orders:read`, revocable grants),\n  never a pasted password or key. Events go out as signed webhooks\n  (`backend-integrations`).\n- JSON in and out; errors as `application\u002Fproblem+json`; an `Accept` you\n  cannot produce gets `406`, or JSON anyway if the project does that.\n- gzip or Brotli for responses over about 1 KB (at the proxy or CDN when\n  there is one), with `Vary: Accept-Encoding`; not for images or archives.\n- CORS lists the origins that may call; never `*` together with cookies or\n  credentials. The origin is matched exactly against config and echoed with\n  `Vary: Origin`; `Access-Control-Max-Age: 7200` (Chromium's cap; without it\n  a preflight is cached 5 seconds and precedes nearly every call);\n  `Access-Control-Expose-Headers` for what the client reads (`Location`,\n  `ETag`, `Retry-After`, `X-Request-Id`, the rate limit fields).\n- Uploads: a size limit, the type checked from the content rather than the\n  extension, a generated name, storage outside the web root (object storage\n  and signed URLs when large), never executed or served with the uploaded\n  type unchecked (`backend-files`).\n- Rate limits on sign-in, sign-up, password reset, anything that sends email\n  or costs money (`backend-security`).\n\n## Check it\n\n- `curl -si` each new endpoint: the status, `Location` on a create, the\n  problem body on a failure; `?limit=1000` clamped, `?sort=passwordHash` 400.\n- The same create sent twice with one `Idempotency-Key` makes one record and\n  replays the same body; a `PATCH` with an old `If-Match` gets `412`.\n- A preflight (`curl -si -X OPTIONS` with `Origin` and\n  `Access-Control-Request-Method`) shows the origin and max age; the OpenAPI\n  lint and breaking-change diff pass, or the break is in the report.\n\n## Avoid\n\nVerbs in paths; `200` with an error inside; a body written to the database\nas parsed; a database row as the response; floats for money; dates without a\nzone; a list with no limit; sort or filter fields concatenated into SQL; a\ncreate that runs twice when the client retries; a weak `ETag` for\n`If-Match`; personal data in URLs; a breaking change shipped under the same\nversion; an endpoint removed without `Sunset` and a date.\n",{"name":5,"description":7},"main","38293fe1b096e6bf3646c7344c38786ed688f464","crates\u002Fenowx-core\u002Fskills\u002Fbackend-api",21,"https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli","https:\u002F\u002Fenowx.ai","https:\u002F\u002Fgithub.com\u002Fenowdev","Pretending to be a Developer","2026-10-06 02:05:35",{"source":8,"skillName":5,"commands":53,"prompt":63,"zipAvailable":64},[54,57,60],{"tool":55,"command":56},"npx","npx skills add enowdev\u002Fenowxcli --skill backend-api",{"tool":58,"command":59},"bunx","bunx skills add enowdev\u002Fenowxcli --skill backend-api",{"tool":61,"command":62},"pnpm","pnpm dlx skills add enowdev\u002Fenowxcli --skill backend-api","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fbackend-api\u002FSKILL.md",true,[],[67,78,95,108,128,147],{"skillNo":68,"name":69,"nameZh":6,"description":70,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":38},"01M6D2HQYSQD9N7MTNDT4A7CBM","demo-skill","Project-scope demo skill for tests.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fworkspace\u002F.agents\u002Fskills\u002Fdemo-skill\u002FSKILL.md",[],[74,75,76,77,22],"demo skill","demo","tests","project",{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":38},"01M6D2HM0GCPM0TM2HPG9HHR2R","writing","Writing words people read: the specific thing instead of claims, words to drop, sentences, interface copy (buttons, labels, errors, empty states, confirmations), page copy, notifications and emails, alt text and link text, numbers and dates, words that translate well, documentation and voice. Read before writing a page's copy, an interface's text or a document.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fwriting\u002FSKILL.md",[],[80,85,86,87,88,89,22,90,91,92,93,94],"text","emails","empty","drop","document","page","voice","notifications","documentation","translate",{"skillNo":96,"name":97,"nameZh":6,"description":98,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":99,"categories":100,"keywords":101,"publishedAt":38},"01M6D2HG07YS49NM196Q0R3AZ8","ui","Designing or restyling an interface: direction, layout, type, colour, icons, components, states, responsive behaviour. Read before building a page, a screen or a set of components.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fui\u002FSKILL.md",[],[97,102,103,104,105,90,106,22,107],"icons","components","SET","responsive","layout","before building",{"skillNo":109,"name":110,"nameZh":6,"description":111,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":112,"categories":113,"keywords":114,"publishedAt":38},"01M6D2HB59HZHWG1RYZDV4SJ91","ui-themes","Light and dark themes, and colour that holds in both: tokens with a value per theme, and what each kind of content needs to stay visible (icons, SVG drawings and line art, logos, photos, screenshots, charts, code, maps, borders, shadows, focus, form controls), switching without a flash, and checking both. Read before building a second theme or a theme toggle, and before any drawing, logo or chart on a page that has two themes.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fui-themes\u002FSKILL.md",[],[97,115,116,117,118,119,120,121,122,22,107,123,90,124,125,36,102,126,127],"ui themes","switching","photos","tokens","drawing","focus","maps","Art","flash","code","Charts","screenshots","logo",{"skillNo":129,"name":130,"nameZh":6,"description":131,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":132,"categories":133,"keywords":134,"publishedAt":38},"01M6D2H5R5KRAE524C8QX0T7Q0","ui-structure","Structure before styling: the blueprint written before any interface code (the screen's job, the regions its kind of page needs, their order and why, the layout skeleton in numbers, the components and their states), the anatomy and order of a homepage, a dashboard, a list, a detail page, settings, a form, sign-in, pricing, docs, an article and a checkout, and how to turn the blueprint into code (tokens, layout primitives, components, sections, page). Read first, before building or rebuilding any page or screen.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fui-structure\u002FSKILL.md",[],[135,97,136,103,137,138,124,139,140,141,106,118,142,143,144,22,107,90,145,146],"structure","ui structure","pricing","dashboard","Blueprint","article","anatomy","styling","primitives","list","why","how",{"skillNo":148,"name":149,"nameZh":6,"description":150,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":151,"categories":152,"keywords":153,"publishedAt":38},"01M6D2H0ZZBJG77MBGPZHA6MWD","ui-stack-vue","Building interfaces in Vue 3 and Nuxt: project layout, script setup with typed defineProps, defineEmits and defineModel, attribute fallthrough, slots and scoped slots, template refs, ref, reactive and computed, watch versus watchEffect, composables and VueUse, provide and inject, Pinia, keyed v-for, transitions, Nuxt 4 (app directory, pages, layouts, useFetch and useAsyncData keys, $fetch in handlers, server routes, runtime config, useSeoMeta, NuxtImg, middleware), VeeValidate forms, Reka UI and Nuxt UI, testing, vue-tsc, and the traps. Read when the project uses Vue or Nuxt.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fui-stack-vue\u002FSKILL.md",[],[97,154,155,156,157,158,159,160,106,77,161,162,22,163,164,165,166,167,168,169],"vue","stack","ui stack vue","forms","pages","watch","runtime","transitions","fetch","pinia","nuxt","template","server","config","directory","testing"]