There are two types of applications in the market first Static application and second Dynamic application. Static application has fixed and unchangeable content whereas Dynamic application change their content based on web services data. The static application can not take or process user data but the Dynamic application has this type of facility. These facilities are generally provided by Web services(also called hosting services). Web Services provides its Server to store or process the data.
Introduction
It is a server-side platform that receives and process request from different types of application irrespective of language and platform.
Web services are an essential component when dealing with an application that is dynamic because most of the applications running these days use web services. Web services provide an application to host their data on the cloud (or servers).
![]()
All web services are API, but all APIs are not web services. Most people get confused about the minor difference between web services and API. Let's understand this in very simple terms. If API is running on any web server then it is a web service or provides any kind of service over the web hence it is called a web service whereas web services can be of many more types like providing SAAS(software as a service), IAAS(infrastructure as a service), PAAS(Platform as a service) these all will provide services but API can also be present of offline like if we have to connect an application to another application within devices so there is no need of a server to be involved in that case.
So now let's have a look at API
API(Application Programming Interface)
An API act as an interface between two different application so they can communicate with each other.
- API is a messenger which delivers the request to the provider and responds.
- API can communicate over a network and also without a network.
![]()
Some popular APIs are as follows,
- Google Map API
- Youtube API
- Facebook Login API
- Gmail login API
How API helps Developers
An API helps developers in many ways some of them are as follows-
- API helps developers to use the third-party application
- Do not reinvent the wheel over and over.
- Efficient product in a short period.
Types of Web Services
There are mainly two types of web services SOAP and REST. Let's understand each one in brief.
![]()
SOAP(Simple Object Access Protocol )
SOAP or Simple Object Access Protocol is a technique to send an XML request over the internet using HTTP protocol and return an XML response. Here envelope is used to send data hence its data transfer is secure. It was used in previous applications and it is a very secure protocol.
REST(Representational State Transfer Protocol)
Any Web Service that is defined on the Principle of REST uses HTTP verbs of getting, POST, PUT, and DELETE.
REST allocates resources on URL and acts. it allows multiple web service-based systems to interact and communicate with them.
![]()
SOAP |
REST |
- This is a function-based protocol.
- It only uses XML.
- It can't be cached.
- It has a strict communication
- Build-in ACID compliance.
- used in banking applications where security is prior.
|
- This is Database based Protocol.
- This Permit HTTP,plain text,XML,JSON
- It can be Cached.
- It has an easy communication
- Lack of ACID compliance
- It is advance and simple
|
REST API mostly uses JSON format so let us see what is JSON.
JSON(JavaScript object Annotation)
It is not a programming language, it s a data interchange format.JSON is mostly used to get and post the data in web services. it is the mostly used formate in today's application development.
- It is a file in which data is written in text formate.
- it is easy and simple to understand
Data types of JSON
- String - "C-sharp Corner"
- numbers - 1,2,-1,-2
- Boolean - true,false
- Array - ["java","python","HTML"] or [2,6,-1]
- object - { "key1" : "value1", "key2": "value2"}
Example of JSON formate,
{
"name": "ravi",
"age": 23,
"email": "[email protected]",
"programming": ["java", "C++", "python"],
"experience": [{
"company Name": "Company1",
"years": 2,
"location": "noida"
} {
"company Name": "company2",
"years": 2,
"location": "noida"
}]
}
How to Create an API in Android
here is a simple Connection API that is used to connect and authenticate our application to web services
<?php
$hostName = 'localhost';
$userName = 'root';
$userPass = '';
$dbName = 'mydb';
$con = mysqli_connect($hostName,$userName,$userPass,$dbName);
if (!$con) {
echo "connection failed";
}
else
{
echo "connection successful";
}
?>
Conclusion
In this article we have learned what is web Services in android and what is API, we have covered the difference between web services and API and after that, we have learned types of Web services SOAP and REST. After that, we have seen the table of REST and SOAP differences, and at last we have seen the JSON format and a simple Connection API.