Tuesday, August 17, 2010

Battle of the APIs: REST vs. RPC

It seems that every time I talk to another developer about building an API, there tends to be some confusion on terminology and implementation details. While many will say that they are implementing a RESTful Web service, when they start detailing the implementation it becomes clear they really mean RPC. I’m not sure where the confusion stems from, as both standards are pretty well documented. Still, I’m amazed at how few REST implementations get it right.

Both REST and RPC have their place, and may even coexist within a single project. They simply provide different ways of accessing things, and each has its own strengths and weaknesses which make it more or less suitable for a given purpose.

What is RPC?

RPC means Remote Procedure Call, and is used to call a function or method exposed on a remote server. When discussing RPC, most developers tend to be referring to either XML-RPC or SOAP. Both are simply protocols, and can be used as completely valid RPC implementations. I’ve also seen many developers happily role their own implementations as well.

Most RPC implementations use XML or JSON to pass messages or payloads between the client and the server. The request message would contain the name of the remote method to call, along with the method arguments. The server would then respond with a message containing the return value of method and any other messages.

If an API uses SOAP, XML-RPC, or uses URLs like http://example.com/api/method?arg1=foo, it is (most likely) an RPC interface. There are many ways to implement an RPC API, but in the last case of a home-grown API, requests might look like those below.

To request a list of user accounts in XML format from an RPC API, the request URI might be similar to this:


The API should send back an XML payload of user accounts, or it may respond with some sort of error message instead. In either case, a 200 OK status code will probably be returned.

The same API may allow the creation of a user account, either using GET or POST (broken apart for readability):

http://example.com/api/createUser \
    ?format=xml \
    &firstName=Example \
    &lastName=User \
    &displayName=Example+User \

In this case, the API would probably respond in much the same way, with an XML payload containing either a success flag or an error string.

What is REST?

The term REST means Representational State Transfer, and is a pretty popular buzzword on the Internet. A RESTful API presents application objects as Web resources, and uses standard HTTP methods and headers to pass information back and forth.

Communication with a REST endpoint is mostly done using the GET, POST, PUT, and DELETE HTTP methods. These roughly translate to read, create, edit, and delete actions, respectively. Parameters are passed using HTTP request headers or query strings, and responses can be returned in a number of formats (XML and JSON being very common). Various HTTP error codes are used to indicate the state of the resource following the request.

The request body of a RESTful call to return a list of of user accounts in XML format may look like this:

GET /api/users HTTP/1.0
Accept: text/xml

The response may be a 200 OK status with an XML payload, or it might be a 401 Unauthorized if the API requires authentication but the credentials were not included with the request.

Creating a new user resource is also very easy, as shown below:

POST /api/users HTTP/1.0
Accept: text/xml
Content-Type: text/xml
Content-Length: 227

<?xml version="1.0" encoding="UTF-8"?>
    <firstName value="Example" />
    <lastName value="User" />
    <displayName value="Example User" />
    <passwordHash value="5f4dcc3b5aa765d61d8327deb882cf99h238" />

If the new user resource was created successfully, the server may respond with a 201 Created status, and a Location header pointing to the newly created resource.

201 Created
Location: http://example.org/api/users/31337

A request to the URI provided in the Location header should return a payload containing the new user record.


Hopefully at this point the basic differences between the two API types are a little clearer. In my opinion, one interface type is not inherently superior to the other, and both can be used very effectively given proper implementations (and documentation!).

While I centered my examples here around a fictional user API which translates well into both interface types, I think it's important to also point out that there are some functions an API might have to support that don't work nearly as well. One such example might be an API which is used to perform some sort of action, such as processing a payment. This type of action would work very well in an RPC interface:

http://example.com/api/processPayment \
    ?format=xml \
    &amount=313.37 \

If you know how to do this in a RESTful way, please share! ;-)


  1. Nice piece of information on HTML5. With the expansion of smartphones and other portable gadgets, the demand for responsive website design that go comfy on all devices keeps on increasing. This leads to invention and expansion of HTM5 web technology. PHP Training in Chennai

    1. Great Article
      Cyber Security Projects

      projects for cse

      Networking Projects

      JavaScript Training in Chennai

      JavaScript Training in Chennai

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

  2. Thanks for your post; selenium is most trusted automation tool to validate web application and browser. This tool provides precise and complete information about a software application or environment. Selenium Training in Chennai | Selenium Course in Chennai | Best Selenium training institute in Chennai

  3. Hi! This is the most often discussion in my office between developers. Thank you for explaning. You have a real talant in writing an essay about most popular developers questions.

  4. It is very good blog for Selenium testing tool. The blog will useful to improve my knowledge about testing. Thanks for sharing this valuable blog.Selenium Course in Chennai | Selenium Training Institute in Chennai

  5. Amazing information,thank you for your ideas.after along time i have studied an interesting information's.we need more updates in your blog.
    Cloud computing institutes in Bangalore
    Cloud Computing Training in Thirumangalam
    cloud computing Training in chennai
    Cloud Computing Training in Sholinganallur

  6. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
    CCNA Training in Chennai
    DevOps Training in Chennai
    DevOps foundation certificate
    DevOps institute certification
    CCNA institute in Chennai
    CCNA Training center in Chennai

  7. I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.

    Best Linux Training Institute in Chennai | Best Linux Training in Chennai | Linux Course | Best Linux Training in Adyar | Best Linux Training in Velachery | Best Linux Training Institute in Tambaram

  8. Nice Article,Great experience for me by reading this info.
    thanks for sharing the information with us.keep updating your ideas.
    German Training in Saidapet
    german language training institutes in bangalore
    learn german language in bangalore
    german language in bangalore

  9. Innovative thinking of you in this blog makes me very useful to learn.i need more info to learn so kindly update it.
    AWS Training in Saidapet
    AWS Training in Nolambur
    AWS Training
    AWS Course in Bangalore

  10. Thanks for providing wonderful information with us. Thank you so much.
    PHP Training in Chennai | PHP Course in Chennai

  11. Really very nice blog information for this one and more technical skills are improve,i like that kind of post.


  12. The development of artificial intelligence (AI) has propelled more programming architects, information scientists, and different experts to investigate the plausibility of a vocation in machine learning. Notwithstanding, a few newcomers will in general spotlight a lot on hypothesis and insufficient on commonsense application. Machine Learning Final Year Projects In case you will succeed, you have to begin building machine learning projects in the near future.

    Projects assist you with improving your applied ML skills rapidly while allowing you to investigate an intriguing point. Furthermore, you can include projects into your portfolio, making it simpler to get a vocation, discover cool profession openings, and Final Year Project Centers in Chennai even arrange a more significant compensation.

    Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account.

  13. Casino and Sports Book by Marriott in Wazala - Mapyro
    Find 속초 출장샵 Casino and Sports Book in Wazala and 거제 출장안마 see 13 photos and reviews. Rating: 4.4 · 포천 출장안마 ‎14 reviews · ‎Price 여주 출장안마 range: 0 거제 출장안마