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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With