DEV Community

Fernando Chata
Fernando Chata

Posted on

Buenas prácticas APIs

Usar nombres de recursos (sustantivos)

❌ GET /querycarts/123
✅ GET /carts/123

Uso de plurales

❌ GET /cart/123
✅ GET /carts/123

Idempotencia

❌ POST /carts
✅ POST /carts {requestId: 123}

Uso de versionado

❌ GET /carts/v1/123
✅ GET /v1/carts/123

Uso de paginado

❌ GET /carts
✅ GET /carts?pageSize=xx&pageToken=xx

Ordenado

❌ GET /carts
✅ GET /carts?sort_by=id

Filtrado

❌ GET /carts
✅ GET /carts?filter=color:blue

Acceso Seguro

❌ X-API-KEY = xxxxx
✅ X-API-KEY = xxxxx
X-EXPIRE = xxxxx
X-REQUEST-SIGNATURE = (URL + QueryString + Expire + Body)

Referencia cruzada de recursos

❌ GET /carts/123?item=321
✅ GET /carts/123/items/321

Agregar un elemento nuevo

❌ POST /carts/123?addItem=321
✅ POST /carts/123/items:add{itemID: "items/321"}

Top comments (0)