Web Services – Chapter 2

RESTFul Web Services – A First Step

Before starting with RESTFul web services , one must be knowing the basics of web services, We have studied basics of web services in our previous chapter, Once you learn basics, it will be great to go ahead.

As we discussed in previous chapter Web services plays a major role in future of web. We will try to learn how the things will be developed, we will have a hands on with development of web services using java. Before starting with web service development we will like to give step-by-step guide for java setup.

We need java sdk installed, tomcat server installed and eclipse as an IDE for development. Web services can be developed with PHP, C# .net , Ruby on Rails. Since our team is comfortable with java, we would like to write further chapters targeting java for the same.

Set-up for Mac Users
Install Java sdk
1> Download jdk 7 from the link

2> Double click on .dmg file , which opens a window and double click on package file as shown in the fig below.

jdk dmg img

3> Click continue in the installation window

4> Enter user name and password of your system

Install tomcat
1> Download tomcat from the link
(Download the zipped file – zip (pgp, md5) )

2> Unarchive the tomcat folder from your download folder.

3> Open the terminal and execute the following commands

These commands are used just to move the tomcat folder into /user/local folder.

sudo mkdir -p /usr/local

sudo mv ~//apache-tomcat-7.0.47 /usr/local

(Usually it will be sudo mv ~/Downloads/apache-tomcat-7.0.47 /usr/local)

4> Create symbolic link for the tomcat – this helps to keep tomcat updated when we get latest tomcat updates.
First create tomcat folder
sudo rm -f /Library/Tomcat

Create symbolic link of tomcat
sudo ln -s /usr/local/apache-tomcat-7.0.47 /Library/Tomcat

5> To make tomcat executable, the ownership of the folder must be changed
sudo chown -R <your_username> /Library/Tomcat

6> To start and stop tomcat we need to run the scripts, to set the execute permission to scripts run the below command

The installation of tomcat is done!
Check whether tomcat starts smoothly or not by starting tomcat with the script
Screen Shot 2014-06-04 at 8.50.01 pm
knowledgecess:~ cess$ /Library/Tomcat/bin/startup.sh

Using CATALINA_BASE: /Library/Tomcat
Using CATALINA_HOME: /Library/Tomcat
Using CATALINA_TMPDIR: /Library/Tomcat/temp
Using JRE_HOME: /Library/Java/Home
Using CLASSPATH: /Library/Tomcat/bin/bootstrap.jar:/Library/Tomcat/bin/tomcat-juli.jar

knowledgecess:~ cess$ /Library/Tomcat/bin/shutdown.sh
Using CATALINA_BASE: /Library/Tomcat
Using CATALINA_HOME: /Library/Tomcat
Using CATALINA_TMPDIR: /Library/Tomcat/temp
Using JRE_HOME: /Library/Java/Home
Using CLASSPATH:
/Library/Tomcat/bin/bootstrap.jar:/Library/Tomcat/bin/tomcat-juli.jar
knowledgecess:~ cess$

In our next chapter let us try to create a sample on web services in Java.

Web Services – Chapter 1

We know a typical client-server communication model , where a client request for useful data and server responds with the valid data over network. The way of communication might differ based on the type of software running at server side, which means if a server is just an ftp server then one has to get the file by running an ftp command, if the type of resource is just a static html page then a simple http get request is sufficient and the communication can be achieved with a suitable communication protocol. The concept of web service gives real boost to the mode of communication between client and server. The client server model becoming more complex than ever with awesome facilities over the internet. Web services are identified as latest technological changes that is enriching the world of business. Software modules written on any language can talk to each other to transfer a set of resources over the internet. This was not the case before web services, with the help of web services both client and server became loosely coupled. With this overview of web services, let us define the web services and understand the concept in depth.

Definition Of Web Services –

Web service is a mode of communication between two devices provided by a software system running at network address over the web, designed and developed to support interoperable machine-to-machine communication over the internet.

The term interoperable in the above definition means a lot when we discuss about web services. The simplest meaning of interoperability is working together, irrespective of the type of communicating devices , both the devices should be able to share the information by exchanging data in the form of specific data format or communication protocols to produce a meaningful result.

To make the concept more clear , let us take an example which describes where and how web services sits in the entire process of communication.

-Assume that you have a set of huge data stored in your server, the data which is collected from your extensive research on physics. If you would like to share your data to the external world in a very meaningful structured way then you can’t just post every data on your website. Because sharing data in a web site is not a structured way , structured way means according to me , share every bit of data but one should use it as per their need.

If one wants data related to astrophysics could be able to fetch only related data, if one wants data related to modern physics could be able to fetch only related data. To achieve this the only best approach is web services.

Develop a software module that query the related set of data from your server and responds to the client by sending only that piece of information. The client here may be of any kind, It might be a mobile application, tablet application, desktop application or web application. Irrespective of the type of client, your software module responds the right information as per the incoming request. Let us understand this with the help of architectural diagram.

Web Services – Architectural Diagram

Architecture Web Services

 

Above diagram is self explanatory which describe about 5 modules , the important point that is clear from the architecture is, a web service software module deployed in the server is capable to process request from any type of client and serve the requested information, this is what we call as interoperability. Web services hence take the web technology to the next level.

How is that Practical –

So far what we discussed is just a theoretical approach of understanding web services. Being a software developer you will be interested to learn how to develop/consume web services. Web services can be developed using any server side

language , Java, C# .net, PHP , Ruby On Rails etc.There are mainly two types of web services SOAP Services and RESTFul services.

1. SOAP Services – Web services can be developed by adopting SOAP protocol , where client-server communication happens by describing the details with WSDL ( Web Service Definition Language ). An XML language will be used to define the message format , which will be sent across the network.

2. RESTFul Services – Representational State Transfer is an information transfer , the services responds to the request with a help of unique service URL and set of data as input for the service. XML is not mandatory , the data can be passed either in plain text or JSON format.

We will learn development of RESTFul web services using Java in our next chapter.