0

I am supposed to design a simple REST API(possibly having only one endpoint) which takes an image as the request body does some processing on it and then give back a response .

The processing can be extracting some crop from the image or making some machine learning predictions.

I am thinking of just exposing a POST endpoint for the service. My confusion from all the REST documentation i find on the internet it says that a POST endpoint should return a status code of 201 created if it is created successfully and should not return some data .

I cannot make a GET endpoint since i think technically it is not possible to send data to GET request endpoint.

Can someone guide me what the HTTP verb should be for the endpoint and is it ok to use POST for this .

Many thanks in advance for any answers.

Subhayan Bhattacharya
  • 5,407
  • 7
  • 42
  • 60
  • There are certain conventions about HTTP methods but technically you may use whichever method you want, return whichever response you want and do whatever you want on server side – mangusta May 25 '20 at 13:44
  • Sounds like PUT would be better suited, as it's idempotent. – Gereon May 25 '20 at 13:46
  • however GET method can't be used for passing body payload so you should use other methods for doing that (not necessarily POST) – mangusta May 25 '20 at 13:47
  • okay then i go ahead with PUT for now . – Subhayan Bhattacharya May 25 '20 at 13:54
  • If you're creating a *REST API* (which is a web server/service that follows a strict set of conventions) then you should follow those conventions to make it easier to use for 3rd parties. If you're creating a web server that does some work, you can do what you want. Not everything that exposes functionality through HTTP is a REST API, or needs to be one. – Tomalak May 25 '20 at 14:31
  • this answer might help you with reasoning which verb to use PUT/POST https://stackoverflow.com/questions/6273560/put-vs-post-for-files-upload-restful-api-to-be-built-using-zend-framework – Teemu May 25 '20 at 15:43

1 Answers1

1

Can someone guide me what the HTTP verb should be for the endpoint and is it ok to use POST for this .

POST is the correct choice. See Fielding, 2009

POST serves many useful purposes in HTTP, including the general purpose of “this action isn’t worth standardizing.”

VoiceOfUnreason
  • 52,766
  • 5
  • 49
  • 91