I was planing to create an API based on microservices, I'm stuck on how to solve a specific scenario.
Initial plan is, all microservices are only accessible through a REST API.
Based on the next schema, if you want to get all the orders you simply go to /orders
and get a list of them.
But whats happens when you want to get all orders related to a client? You go to /clients/123/orders
and internally clients
make a request to orders
and then clients
returns you the orders list, but don't make any sense to make a internal request to orders, receive a long list from orders
and return that list again to the client from clients
. Also the pagination will be a pain here.
I read about having an accessible view of the orders database from clients
but not sure whats is the best approach for this.
/orders?client=123
?/orders/client/123
? "get all orders" is fun while you're testing, but imagine how long that would take you to download from say Amazon.../orders/client/123
or similar. Pagination is fine, you will have to keep track of the relevant current page where paging is implemented .i.e: web client/mobile client etc.. and have a query on the Orders gateway to allow requesting paged data. If the complete list is always very very short you can even return all orders and purely use the client for paging./clients/123/orders
, doesn't mean that the API will make another API call to/orders
. It would just be the same old/orders
call, but will a client ID filter. The REST API is only for the consumer, you're not bound by its interface under the covers.