What is an API?
An API (Application Programming Interface) is a set of rules that allows different
software applications to communicate with each other. It defines methods and data
formats that applications can use to request and exchange information.
Example of API Usage:
A weather app uses a weather API to fetch real-time temperature and forecast data
from a weather service provider.
SOAP vs REST
SOAP (Simple Object Access Protocol)
Uses XML for request and response format.
Works over multiple transport protocols (HTTP, SMTP, TCP, etc.).
Strict structure and follows standards like WS-Security.
Heavier and slower compared to REST.
REST (Representational State Transfer)
Uses JSON, XML, or even plain text as response formats.
Works only over HTTP.
Follows standard HTTP methods (GET, POST, PUT, DELETE).
Lightweight, faster, and widely used for web services.
Example SOAP Request (XML Format)
xml
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:web="http://www.example.com/weather">
<soapenv:Header/>
<soapenv:Body>
<web:GetWeather>
<web:City>New York</web:City>
</web:GetWeather>
</soapenv:Body>
</soapenv:Envelope>
Example REST Request (JSON Format)
HTTP GET Request:
http
GET https://api.weather.com/v1/city/NewYork
Response (JSON Format):
json
Copy
Edit
{
"city": "New York",
"temperature": "20°C",
"humidity": "60%"
}
API Clients
API Clients are tools or applications that interact with APIs to send requests and
receive responses.
Common API Clients:
Postman – Popular for testing REST APIs.
cURL – Command-line tool to make API requests.
Swagger UI – Provides an interactive API documentation interface.
Insomnia – Lightweight API testing tool.
Example Using Postman:
Choose GET method.
Enter https://api.example.com/users in the request URL.
Click Send to see the response.
Status Codes
HTTP status codes indicate the result of an API request.
Status Code Meaning Example
200 OK Request was successful Fetching user data
201 Created Resource was successfully created Creating a new user
400 Bad Request The request was invalid Missing required parameters
401 Unauthorized Authentication failed Invalid API key
403 Forbidden Access denied User lacks permission
404 Not Found The requested resource was not found Invalid endpoint
500 Internal Server Error Server encountered an error API service failure
Example API Response for 200 OK
json
Copy
Edit
{
"status": 200,
"message": "Success",
"data": {
"id": 101,
"name": "John Doe",
"email": "johndoe@example.com"
}
}
Example API Response for 404 Not Found
json
Copy
Edit
{
"status": 404,
"message": "User not found"
}