I know this question has been answered several times, but I am still not sure that providing GET
with long list of non-structured query parameters or POST
to get data is right approach.
I have provided the endpoint:
GET /businessrelationships/{brGlobalKey}
Which returns one resource/object. I would like to provide GET
endpoint (as this is safe method) to get predefined list of objects. I was thinking to firstly use POST
to create new resource, Lists:
POST /businessrelationships/{brGlobalKey}/lists
with Body : {
"brGlobalKeys": [
1234,
212354,
3748
]
}
The POST
will be idempotent and will return listID
, for example 123xyz
. I would then provide GET
to retrieve list with multiple objects:
GET /businessrelationships/{brGlobalKey}/lists/123xyz
Please let me know is this correct method? I know that using 2 instead of 1 call will affect performances, but it is up to the consumer to decide if they want to GET
single resource several times or to use list.
Thanks
I would not recommend to create a separate resource called list
. And I think even if you wanted to have a separate resource, it does not make sense as a sub resource of businessRelationship
.
If the list of the brGlobalIKeys
filter is not too extensive (your example suggests that common API use cases need a handful of keys) I would recommend to use a query string parameter for that taking a comma-separated list of keys and return a filtered array of business relationships. This removes complexity from your service (you don't need to manage the lists of keys) and the client is quite flexible without making additional calls to preconfigure/change the list resource.
Example: https://base.com/businessRelationships?filteredKeys=123,234,345