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:
http://example.com/api/getUserList?format=xml
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 \ &passwordHash=5f4dcc3b5aa765d61d8327deb882cf99h238
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"?> <user> <firstName value="Example" /> <lastName value="User" /> <displayName value="Example User" /> <passwordHash value="5f4dcc3b5aa765d61d8327deb882cf99h238" /> </user>
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.
Conclusion
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 \ &cardNo=4111111111111111
If you know how to do this in a RESTful way, please share! ;-)
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
ReplyDeleteJava Web Services Training in Chennai Java Web Services Training in Chennai Java Web Services Online Training Java Web Services Training in Chennai
DeleteGreat Article
DeleteCyber 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
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
ReplyDeleteHi! 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.
ReplyDeleteIt 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
ReplyDeleteThanks for posting useful information.
ReplyDeleteSelenium Training in Chennai
selenium Classes in chennai
iOS Training in Chennai
Best Android Training Institute in Chennai
Best Android Training in chennai
Useful content, I have bookmarked this page for my future reference.
ReplyDeleteAngularjs course in Chennai
Angularjs Training in Chennai
Blue Prism Training in Chennai
UiPath Training in Chennai
RPA Training in Chennai
RPA courses in Chennai
Amazing information,thank you for your ideas.after along time i have studied an interesting information's.we need more updates in your blog.
ReplyDeleteCloud computing institutes in Bangalore
Cloud Computing Training in Thirumangalam
cloud computing Training in chennai
Cloud Computing Training in Sholinganallur
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.
ReplyDeleteCCNA Training in Chennai
DevOps Training in Chennai
DevOps foundation certificate
DevOps institute certification
CCNA institute in Chennai
CCNA Training center in Chennai
This technical post helps me to improve my skills ,thanks for this wonder post I expect your upcoming blog, so keep sharing...
ReplyDeleteSpoken English in Chennai
Best Spoken English Institute in Chennai
English Coaching Class in Chennai
Best English Coaching Center in Chennai
English Coaching in Chennai
English Coaching Centre in Chennai
English Courses in Chennai
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.
ReplyDeleteBest 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
It is very excellent blog and useful article thank you for sharing with us, keep posting.
ReplyDeleteSpoken English Course in Chennai
English Speaking Course in Chennai
Spoken English Training center in Chennai
Spoken English Classes in Anna Nagar
Spoken English Training in Velachery
Spoken English Training in Tambaram
Spoken English Training in Adyar
Amazing information,thank you for your ideas.after along time i have studied an interesting information's.we need more updates in your blog.
ReplyDeletebest software testing training institutes in bangalore with placements
Software Testing Training in Ambattur
Software Testing Training in Saidapet
Software Testing Training in Perungudi
Nice Article,Great experience for me by reading this info.
ReplyDeletethanks 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
Innovative thinking of you in this blog makes me very useful to learn.i need more info to learn so kindly update it.
ReplyDeleteAWS Training in Saidapet
AWS Training in Nolambur
AWS Training
AWS Course in Bangalore
Awesome Post. Your writing is very unique. The choice of words stood as an exemplary piece of work. Thanks of sharing.
ReplyDeleteHtml5 Training in Chennai
Html5 Courses in Chennai
Html5 Training
Html5 Course
Html5 Training Course
Html5 Training for Beginners
Best Html5 Course
Best Html5 Training
Awesome Post. The choice of words makes this post very unique. Great content. Thanks for sharing.
ReplyDeleteNode JS Training in Chennai
Node JS Course in Chennai
Node JS Advanced Training
Node JS Training Institute in chennai
Node JS Training Institutes in chennai
Node JS Course
Thanks for providing wonderful information with us. Thank you so much.
ReplyDeleteRegards,
PHP Training in Chennai | PHP Course in Chennai
Really very nice blog information for this one and more technical skills are improve,i like that kind of post.
ReplyDeleteoceanofquotes
Education
Thank you so much for your sharing with us and This post is very helpful for gain my knowledge...
ReplyDeleteOracle DBA Training in Chennai
oracle dba training
Excel Training in Chennai
Oracle Training in Chennai
Spark Training in Chennai
Tableau Training in Chennai
Excel Training in Chennai
Embedded System Course Chennai
Unix Training in Chennai
Thanks for updating this information. Good job.
ReplyDeletepersonalised mugs india
photo mugs online india
rent a laptop in chennai
laptop rental in tambaram
how to register a company in chennai
business registration in chennai
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.
ReplyDeleteProjects 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.
Thanks for sharing such a helpful, and understandable blog. I really enjoyed reading it.
ReplyDeleteRobots for kids
Robotic Online Classes
Robotics School Projects
Programming Courses Malaysia
Coding courses
Coding Academy
coding robots for kids
Coding classes for kids
Coding For Kids
Casino and Sports Book by Marriott in Wazala - Mapyro
ReplyDeleteFind 속초 출장샵 Casino and Sports Book in Wazala and 거제 출장안마 see 13 photos and reviews. Rating: 4.4 · 포천 출장안마 14 reviews · Price 여주 출장안마 range: 0 거제 출장안마