Chatty interaction with one resource over coarse response with multiple resources
Fine-grained resources allow for simpler caching strategies
Specialized resources can simplify API interactions and reduce complexity and maintenance.
Changing any attribute on a booking in a single request multiplies complexity. Clients only modify some attributes at a time, so we can make simpler API interactions to support that.
PUT /bookings/:id
- modify pickup, dropoffPUT /bookings/:id/coverages
- modify booking coveragePUT /bookings/:id/fleet
- modify booking fleetUse specific HTTP codes when applicable, not just 200, 400
GET
resource to avoid mass duplication of responses, not including collections, search functionality.GET
/cars/:id returns JSON representation of a Car
in response body with a 200 response codePOST /cars
returns Location
header with https://api.dealerware.com/cars/2
without a response bodyPUT /cars/2
returns 204 response code without a response body, client can refresh state with GET /cars/2
GET /cars/search
returns 200 response code with collection of Car
in response body, may (but not must be) same response body as GET /cars/:id
GET /cars
returns 200 response code with collection of Car
in response body, may (but not must be) same response body as GET /cars/:id
GET /cars/2
has an attribute links
{ "id": 2, "make": "Audi", "links": { "fleet": { "id": 4, "href": "https://api.dealerware.com/fleets/4" } } }
{ "odometer": { "value": 12.34, "unit": "km" } }
url
attributeAccept
values: application/json
, application/*
, */*
application/json
or multipart/form-data
Total
- total number of recordsPage
- current page number returnedPer-Page
- number of records returned per pageLink
headerLink
header contains array of linkshttps://api.dealerware.com/locations?page=1; rel="first", https://api.dealerware.com/locations?page=10; rel="last", https://api.dealerware.com/locations?page=2; rel="next"
page
query paramGET /locations?page=2
page_per
query paramGET /locations?page=2&per_page=100
/reservations
, /reservations/:id
/reservation
, /reservation/:id
GET /user/drivers_license
instead of GET /user/drivers_license
car_reservation
car-reservation
, CarReservation
, carReservation
GET /rentals/1/emails/receipt
over GET /rentals/1/email_receipt
address
attributes within location
{ "id": 1, "name": "Audi Dealership", "address": { "id": 3, "line1": "211 E 7th St" } }
car
in this Example{ "car": { "id": 1, "make": "Audi" } }
{ "id": 1, "make": "Audi" }
Accept
values: application/json
, application/*
, */*
application/json
or multipart/form-data
sort
query param, using optional -
operator for ascending vs descendingsort=location_id,created_at
- sort by location_id asc, created_at ascsort=location_id,created_at
-sort by location_id asc, created_at descsort=location_id,created_at
-sort by location_id desc, created_at desc