It's fairly common to have an API gateway to route traffic from the main URL to a specific microservice. The way you set up the URLs within your microservice really depends on the idioms you choose. In essence, your microservice is the bounded context for the nouns you've identified (Payments
, Customers
, Orders
).
So your API Gateway does the core routing:
The temptation then is to simply have the REST endpoints at the very root of your microservice. Exampled:
- GET / -> list
- POST / -> create
- GET /{id} -> get record
- POST /{id} -> update record
- DELETE /{id} -> delete record
However, you may be hampered by your framework. For example in my team's project we found that the Spring Boot infrastructure wouldn't show the Swagger-UI if everything was at the root like that. For that reason we had to add the verbs to the URL. We still use the HTTP Methods, but the URL mapping looks more like this:
- GET /list -> list
- POST /new -> create
- GET /get/{id} -> get record
- POST /update/{id} -> update record
- (we don't delete)
The main take-aways from this would be the following:
- Don't overthink it.
- Whatever you choose, be consistent
- And if something isn't working, adapt
Consistency is more important than any notion of "purity" or "best", because if one service implements the URL pattern one way and another service does it differently for the same type of functionality--then you are making the consumers of your API pay for it.