Gyrien
Gyrien

Reputation: 317

SOAP vs REST in a non-CRUD and stateless environment

Pretend I am building a simple image-processing API. This API is completely stateless and only needs three items in the request, an image, the image format and an authentication token.

Upon receipt of the image, the server merely processes the image and returns a set of results. Ex: I see five faces in this image.

Would this still work with a REST based API? Should this be used with a REST based API?

Most of the examples I have seen when comparing REST and SOAP have been purely CRUD based, so I am slightly confused with how they compare in a scenario such as this.

Any help would be greatly appreciated, and although this question seems quite broad, I have yet to find a good answer explaining this.

Upvotes: 0

Views: 174

Answers (1)

user1907906
user1907906

Reputation:

REST is not about CRUD. It is about resources. So you should ask yourself:

What are my resources?

One answer could be:

An image processing job is a resource.

Create a new image processing job

To create a new image processing job, mak a HTTP POST to a collection of jobs.

POST /jobs/facefinderjobs
Content-Type: image/jpeg

The body of this POST would be the image.

The server would respond:

201 Created
Location: /jobs/facefinderjobs/03125EDA-5044-11E4-98C5-26218ABEA664

Here 03125EDA-5044-11E4-98C5-26218ABEA664 is the ID of the job assigned by the server.

Retrieve the status of the job

The client now wants to get the status of the job:

GET /jobs/facefinderjobs/03125EDA-5044-11E4-98C5-26218ABEA664

If the job is not finished, the server could respond:

200 OK
Content-Type: application/json

{
  "id": "03125EDA-5044-11E4-98C5-26218ABEA664",
  "status": "processing"
}

Later, the client asks again:

GET /jobs/facefinderjobs/03125EDA-5044-11E4-98C5-26218ABEA664

Now the job is finished and the response from the server is:

200 OK
Content-Type: application/json

{
  "id": "03125EDA-5044-11E4-98C5-26218ABEA664",
  "status": "finished",
  "faces": 5
}

The client would parse the JSON and check the status field. If it is finished, it can get the number of found faces from the faces field.

Upvotes: 1

Related Questions