Converting an RPC Web Service to a REST Service

I am converting a SOAP-based RPC-style web service to a JSON-based REST web service using ASP.NET web API. Methods such as AddXYZ / UpdateXYZ / RemoveXYZ correctly display HTTP verbs for POST / PUT / DELETE. Are there any best practices / guidelines for matching typical RPC type operations, such as ExecuteXYZ or AssignXYZ methods, to its REST? I believe that such operations will be mapped to the corresponding URLs such as "ExecuteXYZRequest" and "AssignXYZRequest"

http://myhost/myservice/ExecuteXYZRequest http://myhost/myservice/AssignXYZRequest 

The execution request "ExecuteXYZ" then translates into a POST operation.

The receipt of the submitted request will be translated into GET (usually this will be used to obtain the status of the sent request).

 http://myhost/myservice/ExecuteXYZRequest/1 <--- 1 is the ID of the request 

Canceling a request (subject to cancellation) will result in a DELETE

POST will not actually be displayed.

Does this mean that this seems like a reasonable implementation of REST, or am I completely out of my mind here? Thought / leadership praised.

UPDATE Here is an example I'm trying to model: From many to many relationships between a Contact and Event object. What would be the best way to model the membership of a contact with an event as a REST resource so that the Contact can be added / removed from the event. On RPC land, it will be a method such as "AssignContactToEvent", which takes the identifiers of both objects and establishes a connection between the two. How it can be naturally modeled in REST as a resource. I remember that there is a concept of links and "rel", but I cannot find a concrete practical example illustrating how to model something like this using the Web API

+4
source share
3 answers

The question is whether it makes sense for the RPC methods to appear in the REST of the resources indicated in the message

In a nutshell; no, it makes no sense to map methods to resources the way you describe :)

To successfully "make REST", we must think a little differently and abandon all the thoughts of RPC and CRUD operations; they are really quite limited once you turn on RESTful!

Key abstraction of information in REST is a resource. Any information that can be called can be a resource: a document or image, temporary services (for example, "today is the weather in Los Angeles"), the collection of other resources, not a virtual object (for example, a person), and so on. In other words, any concept that may be the target of an author hypertext link must meet the definition of a resource. A resource is a conceptual mapping to a set of objects, not an object that corresponds to a mapping at any particular point in time. http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

A method or action / verb then is not a resource, so it does not belong in a URI - unless, of course, you create an application that allows people to create their own methods, which would be quite unusual!

Taking your specific example for contact and event relationships , it’s important to understand that your AssignContactToEvent is an action that occurs under the Web-API layer and cannot be modeled RESTfully; Hope this becomes clear in the following examples :)

First we need good resources to simulate a list of all contacts and a list of all events:

 /contacts /events 

These resources model an individual contact or event identified by an identification marker:

 /contacts/{contact_id} /events/{event_id} 

Users of your application want to know who is participating in a particular Event, so we need a resource that models the list of participants in the event:

 /events/{event_id}/participants 

When we want to add a contact to the event, we could POST get the minimum Contact representation (containing only Contact-ID) in the list of participant participants:

 POST /events/{event_id}/participants/ HTTP/1.1 Content-Type: application/json {'id': {contact_id}} 

Removing a contact from an event:

 DELETE /events/{event_id}/participants/{contact_id} HTTP/1.1 

Your user applications also want to see at a glance the events in which the Contact participates, therefore, to simulate this, another resource is required:

 /contacts/{contact_id}/events 

Similarly, you can now get a list of events for a contact and assign events using POST:

 POST /contacts/{contact_id}/events/ HTTP/1.1 Content-Type: application/json {'id': {event_id}} 

An important point to take on board is that whenever you need to model something new, you create a resource. Information about how you store the properties and relationships of data objects is distracted by the web API. In fact, the storage technology may change in the future, say, from a relational relation to the object store, or you will change your programming language or framework, but in all cases your URI (and web API) will remain the same. REST and HTTP are designed to survive far beyond the technologies that work under the hood.

As a final example of creating new resources, consider a resource that models a list of contacts that have the role of organizer:

 /events/{event_id}/organisers 

or one that models the list of events that Contact organizes:

 /contacts/{contact_id}/events-organised 

If you have an authentication system, you can see the events you attend:

 /my-account/events 

Hope this helps clarify the purpose of the web API and follow RESTful principles.

+7
source

There are two approaches that I have seen so far.

One is to compare action with a verb if there are very few actions so that there is no collision. So if the action is unsafe and idempotent, then POST , otherwise if it is not safe, but idempotent, then PUT :

 POST http://myhost/myservice/XYZ 

Another is to define an action as a logical resource:

 POST http://myhost/myservice/XYZ/Assignment 

Richer later, and I approve of it.

+2
source

Some important points

  • RPC Endpoint -> REST Entry Point

  • RPC reading method -> REST GET on Resource

  • RPC creation method -> REST POST operation

  • PRC delete method -> REST DELETE operation

  • Post SOAP SOAP -> REST PayLoad

additonaly, think of cache headers, Content-Type headers like @Consumes, @Produces

+1
source

All Articles