-3

I have a HATEOAS API (in ASP.NET) with an endpoint: POST /api/messages - to create a new message and it returns the location of a new message

Now I have a requirement that in some cases based on message data, it should create multiple messages instead of one. So there is no single location to get a message.

What should I return when posting now to the endpoint which might have 1 or more created messages?

Should it be a location where I can get all new messages (messages could have some group ID)?

Or should I leave API as is and rely on the front-end to create each separate message? But then business logic will be in the front-end which I do not want and with multiple clients, they would have to implement the same logic too.

1
  • Is there any reason why this question was downvoted? Could one explain?
    – MarisKs
    Commented Apr 11 at 12:28

1 Answer 1

4

What should I return when posting now to the endpoint which might have 1 or more created messages?

How would you do it if your clients were web browsers?

You'd presumably return a "status of the action", reporting that the request was handled correctly with HTML links to each of the resources of interest to the client (and presumably some context information, so that clients can distinguish the links from each other).

So do that.

(It may be useful to review the text of the registered references for HTTP 200 and HTTP 201.)

1
  • When I am creating a new resource and the result is only one resource, then I am returning status 201 and the URL of the new resource in the Location header. That confused me - the Location header can point only to one resource, but when I am creating multiple resources, I need to return multiple URLs. Then as I understand, best way is to return those links in the response content body.
    – MarisKs
    Commented Apr 11 at 12:21

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