Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTful way to trigger server-side events

I have a situation where I need my API to have a call for triggering a service-side event, no information (besides authentication) is needed from the client, and nothing needs to be returned by the server. Since this doesn't fit well into the standard CRUD/Resource interaction, should I take this as an indicator that I'm doing something wrong, or is there a RESTful design pattern to deal with these conditions?

like image 561
NFicano Avatar asked Dec 13 '11 16:12

NFicano


1 Answers

Your client can just:

POST /trigger

To which the server would respond with a 202 Accepted.

That way your request can still contain the appropriate authentication headers, and the API can be extended in the future if you need the client to supply an entity, or need to return a response with information about how to query the event status.

There's nothing "non-RESTful" about what you're trying to do here; REST principles don't have to correlate to CRUD operations on resources.


The spec for 202 says:

The entity returned with this response SHOULD include an indication of the request's current status and either a pointer to a status monitor or some estimate of when the user can expect the request to be fulfilled.

You aren't obliged to send anything in the response, given the "SHOULD" in the definition.

like image 152
Rob Hruska Avatar answered Oct 13 '22 11:10

Rob Hruska