Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTful processing function/resource: GET or POST?

I am creating a RESTful web service and some of the resources are computing or processing functions. For instance, it is possible for a user to scale and convert images through the API by submitting an image and receiving the scaled or converted image back.

According to the RESTful Web Services Cookbook, section 2.5, I should use GET:

Treat the processing function as a resource, and use HTTP GET to fetch a
representation containing the output of the processing function. Use query
parameters to supply inputs to the processing function.

This is clear for cases where the inputs are simple (such as the long/lat coordinates of a point). However, should I follow the same advice for larger inputs such as images? As far as I know it is not possible to send this much data as a query parameter.

like image 840
Mauritz Hansen Avatar asked Jan 18 '12 14:01

Mauritz Hansen


People also ask

Does REST API use GET or POST?

GET requests should be used to retrieve data when designing REST APIs; POST requests should be used to create data when designing REST APIs. Creating something is a side effect — if not the point. The HTTP GET method isn't supposed to have side effects. It's considered read-only for retrieving data.

Should I use POST instead of GET?

Using POST instead of GET would prevent the client from having to worry about encoding values and data size, since data would be sent in the body, rather than as a URL parameter.

Why would you use POST instead of GET for a read operation?

But in general terms GET is used when server returns some data to the client and have not any impact on server whereas POST is used to create some resource on server.

Which of these are the 4 correct types of REST requests?

The most common are: GET, POST, PUT, and DELETE, but there are several others. There is no limit to the number of methods that can be defined and this allows for future methods to be specified without breaking existing infrastructure.


1 Answers

Use POST. In effect you are doing an Image Upload and processing on the server. Can't think of another way to do it unless the image is already stored on the server.

like image 69
Sid Avatar answered Oct 27 '22 10:10

Sid