- A web service is a standard used for exchanging information between applications or systems of heterogeneous type.
- Software applications written in various programming languages and running on various platforms can use web services to exchange information over the Internet using http protocol.
Why Web Service?
Expose method as a service over the network
- Web service is a chunk of code written in some programming language (Say C# or Java) that can be invoked remotely through http protocol.
- Once the Web methods are exposed publically, any applications can invoke it and use the functionality of the web methods.
Application Inter-operability – Connect heterogeneous applications
- With the help of web service, heterogeneous applications (Java and PHP application) can communicate with each other.
- Moreover, Web service written in Java can invoke from PHP by passing the required parameters to web methods.
- This makes the applications platform and technology independent.
- Web Services uses standardized industry standard protocol for the communication which must adhere and followed by the applications creating Web Service.
Cost effective communication:
- Also, Web service is using SOAP over HTTP protocol for communication. Which is much cheaper than systems like B2B.
RESTFul Webservice Request and Response – Drill-down
- The first step in designing RESTFul web service is choosing the right domain name – say weatherinfo.org to retrieve weather information of cities.
- Let us take the first example (weatherinfo.org) which takes city name as input, composes weather information of the city and respond back to the browser.
- Also, Assume the response is in XML format, this can be in other formats like JSON as well.
- Moreover, Here is the structure of Request and Response:
Moreover, The client request from the browser will look like:
So, GET http://weatherinfo.org/getweather/mumbai HTTP/1.1
The server response will look like
HTTP/1.1 200 Ok
Date: Mon, 14 Apr 2014 10:20:58 GMT
<City name=”Mumbai” datetime=”2014-04-14 10:20:58 GMT” >
<Condition>Scattered Clouds</Condition >
- Line 1 is the initial line which has the HTTP response code – 200 OK, lines 2 through 4 are the HTTP headers, line 5 is the mandatory blank line separating header and body. Moreover, And lines 6 through 10 constitute the “HTTP Body (or content)”. Moreover, This part is the data that the response carries and can be in any format, not necessarily XML.
Advantages of using RESTful web services
- RESTful Web services designed with less dependence on proprietary middleware (for example, an application server) than the SOAP- and WSDL-based kind.
- Moreover, The great fit between Ajax and REST has increased the amount of attention REST getting these days.
- Also, Exposing a system’s resources through a RESTful API is a flexible way to provide different kinds of applications with data formatted in a standard way. It helps to meet integration requirements that are critical to building systems where data can easily combine (mashups) and to extend or build on a set of base, RESTful services into something much bigger.