Tuesday, November 15, 2016

API Testing -- HTTP and REST, the difference exist


From the last post in this series, I'm continuing to share my learning and till day practice in testing the APIs. In this context, this post will have information on below mentioned.

  • HTTP and REST, the difference exist

I wish to keep the below topics in the next post so that it helps in gaining the clarity of RESTful APIs with different protocols.
  • The usual in the WEB API testing
  • The "not thought about" in testing APIs -- Web and RESTful


HTTP and REST, the difference exist

HTTP is a protocol and one of the way to transfer the files. This will connect the pages in the World Wide Web. While the REST is set of constraints documented for the architectural style for web. This constraints are to ensure the scalability and ease use of the web systems.

The common understanding for an engineer is the web runs on HTTP and so the RESTful API.Yes, the REST API will use and can use HTTP as communicating and transfer protocol. This understanding is common because one might see HTTP being used often and most times with RESTful APIs. But it is not mandate that RESTful API should always use HTTP only.  The RESTful API can also be for FTP, SMTP and other protocols to transfer and communicate.

Now let me reiterate this line again from above paragraph,
"While the REST is set of constraints documented for the architectural style for web"
The web has many protocols to communicate and transfer; one among them is the HTTP. So now we know the idea that RESTful API can be designed and used for any communicating and transfer protocols other than HTTP.

Then the difference between REST and HTTP to mention here in short is as below:
  1. HTTP API is the any API which makes use of HTTP as its protocol.
  2. RESTful API sticks on to all REST constraints which are described in the dissertation of Roy Fielding.
Usually the 'Web API' is referred to HTTP API. However it is good to seek clarity when one hears "it is the Web API".  That means, SOAP can also be HTTP API if it uses HTTP. If the SOAP can use HTTP for transfer and communication, then RESTful API are possible for SOAP as well over HTTP, isn't it?  This looks to be tricky in understanding but it is not. Spending sometime to ponder and explore on this area, will give the clarity in learning this.


3 comments:

  1. Ravi..Thanks for posting such detailed analysis based post on API testing. I have a question though. When you say "RESTful API are possible for SOAP as well", I interpret it as follows...

    1. A SOAP protocol based XML Request (which is a valid instance of the WSDL defined for that particular service's Request) to a RESTful API can be sent over HTTP
    2. The Representational State of the object (Response), then, can be passed over HTTP protocol to the client, again in the XML format (a valid instance of WSDL)

    Is above interpretation correct?

    ReplyDelete
    Replies
    1. Hello Sandeep,

      To start, we will pick Transport protocol and Messaging protocol.

      HTTP is an application protocol and also used to transfer the hypertext. Likewise, SOAP is a messaging protocol and uses the application protocols to transfer the messages. Commonly, the SOAP uses HTTP/S to transfer the messages.

      1. A SOAP protocol based XML Request (which is a valid instance of the WSDL defined for that particular service's Request) to a RESTful API can be sent over HTTP

      Yes. The message is conveyed in the XML format by SOAP. The HTTP header supports to specify what is the content type and what it accepts with headers -- Content-Type and Accept. RESTful sending or/and receiving JSON, XML, Text or any defined type (provided it is usable over HTTP) is possible.

      And we know, SOAP carries the message in its style over the communication line i.e. HTTP. For example it as this, On mobile phone I can talk to people and convey the same message in different languages to people who speaks that respective language. To relate and learn, here the mobile phone network act as the HTTP and message I'm sending in respective language with its words is like SOAP. That means I can make use of mobile phone network to design the best way of sending the messages irrespective of the language while I know how to communicate in that language.


      2. The Representational State of the object (Response), then, can be passed over HTTP protocol to the client, again in the XML format (a valid instance of WSDL)

      Now from above learning which we have observed, transfering the message in XML format (WSDL) over HTTP by SOAP is possible.


      Hope I have answered the queries. If not, let me know.

      Delete
    2. Sandeep,

      The first two rules shared in below blog post helps to have clarity on transfer and messaging protocol and design of RESTful API.

      http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven

      Delete

Please, do write your comment on the read information. Thank you.