26
loading...
This website collects cookies to deliver better user experience
/api/v2/customers/24/orders/1
/products/56/variants
/api
all the way.https://api.mydomain.com
where this becomes more redundant... /api/v1
or /api/v2/
and so on...GET
request should invariably never have side effects -- that is it shouldn't change the state of a resource... talking of resources...Users
or Customers
or Orders
etc.CapitalCase
, camelCase
, kebab-case
, snake_case
, etc. A URL is not a programming language, stick to kebab-case
- URLS are case insensitive and you enhance readability by exposing the idiosyncrasies of your back-end language to your user!GET /api/v1/customers
GET /api/v1/users
GET /api/v1/orders
GET
request should expect this to be done via query strings GET /api/v1/customers?page=1&page_size=20
GET /api/v1/customers/12
GET /api/v1/users/1
GET /api/v1/orders/24
GET /api/v1/customers/1?fields=id,firstname,lastname
application/json
or application/url-form-encoded
or whatever you requirePOST /api/v1/customers
201 { "id": 12, "name": ... }
PUT /api/v1/customers/1
200 { "id": 1, "name": ... }
PUT
(see above) or PATCH
. PATCH is usually reserved for partial updates of a resource. DELETE
is well, for removing a resourcePUT /api/v1/customers/1
200 { "id": 12, "name": ... }
PATCH /api/v1/customers/1
200 { "id": 1, "name": ... }
DELETE /api/v1/customers/1
200
Customer
might have Orders
or Bussiness Units
or even a single one-to-one attribute like Address
GET /api/v1/customers/1/orders
GET /api/v1/customers/1/orders/1
POST /api/v1/customers/1/orders
GET /api/v1/customers/1/business-units
GET /api/v1/customers/1/address
POST
it! And put it in the request body, these things can show up in browser histories and server logs and are a big no no!POST /api/v1/auth/login
{
"username": "...",
"password": "..."
}
Address
), or when the resource cant really be pluralised (hello Advice
or Evidence
)