What is web service (SOAP and REST)

Web services are most important while creating any dynamic application the main thing that we need to take care about

Web Service :- It is peace of code if we take a small operation that runs on the server which gives us Response when we call server Methods.

Types of Web services

  1. Simple Object Access Protocol (SOAP)
  2. Representational State Transfer(REST).

Architecture of Web services


REST :- it is a Representational State Transfer used to create public API(Application Program Interface) in which if you consider your developing mobile or website application now you have to do database operation so usually what we do need database and need to host script somewhere on server we call scripts by calling URLs and it works the same with database.

when we use web service that means your not calling your database Insert or update file your calling methods and those methods will return you something as per the request.

it is a more secure way to do CRUD operation.

REST use JSON as response and JSON can carry any data that why nowadays REST is used almost in every second application in the industry.

Example Code

// HTTP Get Method
// Path: http://localhost/<appln-folder-name>/login/dologin
// Produces JSON as response
public String doInsert(@QueryParam(“Name”) String Name, @QueryParam(“Username”) String Username, @QueryParam(“Password”) String Password, @QueryParam(“Mobile”) String Mobile, @QueryParam(“Address”) String Address, @QueryParam(“City”) String City) {
String response = “”;
//System.out.println(“Inside doLogin “+uname+” “+pwd);
int retCode = registerUser(Name, Username, Password, Mobile, Address, City);
if (retCode == 0) {
response = Utility.constructJSON(“register”, true);
} else if (retCode == 1) {
response = Utility.constructJSON(“register”, false, “You are already registered”);
} else if (retCode == 2) {
response = Utility.constructJSON(“register”, false, “Special Characters are not allowed in Username and Password”);
} else if (retCode == 3) {
response = Utility.constructJSON(“register”, false, “Error occured”);
return response;


Above code is just a sample for creating HTTP method using JAX-RS jersey framework It is a big concept we need to Study more for write own services….

Below example is working you can Test API given




SOAP :- It is used everywhere as popular protocol for web services as REST use to do CRUD operation over HTTP methods but SOAP is used for different purpose like Accessing Application logic over HTTP URLs

SOAP return XML as response.