In a previous blog post, I outlined my solution to summary routes, in short, every route in my API will have a matching summary route, the summary route is simply the route with a summary/
prefix.
If the GET endpoint of a route supports parameters the summary route should support the same parameters, in my experience, it will need additional parameters; as always, best shown with an example.
The summary route lives at summary/resource-types/[resource-type]/resources/[resource]/items
, the GET endpoint has eight parameters, below I’ll show the expected output for each parameter.
In my API I have the following route /resource-types/[resource-type]/resources/[resource]/items
. The GET endpoint returns a collection of the items assigned to the resource; it has four parameters for filtering, year
, month
, category
and subcategory
.
No parameters | Total sum of items
years
| Summary for each year
year
| Summary for the requested year
months
| Summary for each month
month
| Summary for the requested month
categories
| Summary for each category
category
| Summary for the requested category
subcategories
| Summary for each subcategory
subcategory
| Summary for the requested subcategory
So far I’ve not come across any negatives to this structure, yes, there are numerous parameters for the GET endpoint, I don’t consider that an issue, I’d rather have fewer routes than fewer GET parameters.