3

I'm building a microservice, which goal is to manage a specific aspect of data for an entity. There is another microservice that manages (create and holds basic data) for that entity.

I wish that accessing an entity in my new microservice will be done using the same ID as with the other service, so that all other microservices that need to access the new service will be able to do so using the "entity's ID".

So when creating (or setting for the first time) the resource in my new service I need to already receive its "external ID". Is it "RESTful" (enough) to receive that ID as part of the POST URL, or must I omit the ID and have it set as part of the request's body?

For example, can I use this to create / set for the first time the object in my service:

POST http://domain:port/resource/:ExternalID 
  • Does this answer your question? [REST: Updating resource by different identifier?](https://stackoverflow.com/questions/52149235/rest-updating-resource-by-different-identifier) – Denis.E Jan 26 '22 at 15:11

1 Answers1

-1

Yes, this is RESTful enough :)

As long as the ExternalID is unique, then that is fine to use as the resource identifier. Whether you use it internally as your primary key or store it as another property is your choice.

Typically though a POST to the http://domain:port/resource endpoint would create your resource, and give it an Id.

According to the HTTP RFC a PUT request can be used as an upsert:

The PUT method requests that the state of the target resource be created or replaced

So perhaps that would be better suited to what you are doing.

Community
  • 1
  • 1
jmc
  • 1,058
  • 1
  • 12
  • 20