I am designing an API and am wondering the best practice for values that can either specify a number or a list of items, or just specify that it is 'all' of those items.
For example imagine an endpoint /analyze that allows you to analyaze a document for specific categories. A sample request might be:
{
"documentId": "my-doc",
"numberOfLines": 100,
"categories": ["category1", "category2"]
}
What would be the best way to signify that I want all lines and all categories? Have multiple types for the same value like this seems like a bad pattern:
{
"documentId": "my-doc",
"numberOfLines": "all",
"categories": "all"
}
Is it best to have something like null
or -1
signify all. I don't like this because it could cause errors if that logic is missed by the handler:
{
"documentId": "my-doc",
"numberOfLines": null, //null to mean all
"categories": null // null to mean all
}