1

With a monolith we have one huge api project for which we used plural nouns to represent each entity. For example http://monolith.domain.com/Payments, http://monolith.domain.com/Customers, http://monolith.domain.com/Orders, etc.

With the microservice architecture, we now have the plural noun as the microservice itself. So what is the best practice for naming the endpoints?

3
  • get, create, update, remove ;).
    – Fabio
    Commented Dec 6, 2019 at 7:55
  • No, that is to be understood from the http protocol - GET, POST, PUT, DELETE respectively. I am asking about endpoint names
    – variable
    Commented Dec 6, 2019 at 8:13
  • teamjohnston.net/blog/2016/06/08/… Commented Oct 31, 2020 at 17:35

2 Answers 2

2

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.

3
  • What is an example of an API gateway tool.
    – variable
    Commented Jun 30, 2021 at 3:15
  • Google is your friend :-)
    – Laiv
    Commented Jun 30, 2021 at 7:57
  • There are products called API gateways, but a kubernetes Ingress service does the trick just as well. Their sole function is to route URLs to an instance of your service. Commented Jun 30, 2021 at 12:16
0

Regarding what I am working with microservices architecture, the structure of our endpoints should be as follows:

http(s)://domain.com/{service-name}/{api-version}/

Thus, the action of endpoints is determined by HTTP action: GET, POST, PUT, DELETE

1
  • How does your service distinguish between entities? Or does it have only one entity?
    – John Wu
    Commented Jun 28, 2021 at 18:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.