I am trying to create a Put endpoint using rest. Let's say that under the link
I am trying to add a new address (if that id doesn't exist) or I'm trying to update it if it does already exist.
My application has several layers Controllers, Services, Models and Repositories. Given the fact that the business layer decides if an update or an add is required (this logic takes place in the service layer and below), how would the controllers be able to find out if an update or an add happened and return the correct status codes (201 for resource created, 204 if just an update has occured)?
My only ideas are to return some sort of result object, but that doesn't feel particularly correct. For the cases where the service methods are not void, they usually return DTOs.
LE: I think I didn't express myself correctly to what the use case is (my example might be a bit stretched). The address resource already has an id, this is why I am not doing a post. Imagine the following endpoint:
Here I am trying to add an address with a particular id as a subresource to a street. The reason for which I am not using Post in such a case is because I am not creating a new address and the existing one presumably exists with that same id and can be found at
Consequently, for adding such a resource to a particular street, would it still make sense to post it? In my mind, this is where a Put is required, as you wouldn't want to randomly generate different ids for addresses.