Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper RESTful way to handle a request that is not really creating or getting something?

Tags:

rest

I am writing a little app that does one thing only: takes some user-provided data, does some analysis on it, and returns a "tag" for that data. I am thinking that the client should either GET or POST their request to /getTag in order to get a response back.

Nothing is stored on the server when the client does this, so it feels weird to use a POST. However, there is not a uniform URI for the analysis either, so using a GET feels weird, since it will return different things depending on what data is provided.

What is the best way to represent this functionality with REST?

like image 475
jergason Avatar asked Oct 09 '22 02:10

jergason


1 Answers

The "best way" is to do whatever is most appropriate for your application and its needs. Not knowing that, here are a few ideas:

  1. GET is the most appropriate verb since you're not creating or storing anything on the server, just retrieving something that the server provides.

  2. Don't put the word get in the URI as you've suggested. Verbs like that are already provided by HTTP, so just use /tag and GET it instead.

  3. You should use a well-understood (or "cool") URI for this resource and pass the data as query parameters. I wouldn't worry about it feeling weird (see this question's answers to find out why).

To sum up, just GET on /tag?foo=bar&beef=dead, and you're done.

like image 98
Brian Kelly Avatar answered Oct 13 '22 10:10

Brian Kelly