Introduction to APIs
• • REST, SOAP, GraphQL & API Testing with
Postman
• • Understanding the Building Blocks of
Modern Web Communication
What is an API?
• • API = Application Programming Interface
• • Allows applications to communicate
• • Like a contract between components
Why APIs Matter
• • Enable integration between systems
• • Power web and mobile apps
• • Enable automation and cloud services
Types of APIs
• • REST (most common)
• • SOAP (legacy, structured)
• • GraphQL (modern, flexible)
REST API
• • Representational State Transfer
• • Stateless, uses HTTP methods
• • Typically returns JSON
• Example:
• GET https://api.example.com/users/2
• Response:
• { "id": 2, "name": “tomy Doe", "email": "
[email protected]" }
SOAP API
• • Simple Object Access Protocol
• • Uses XML, strict format
• • Used in enterprise systems
• Example:
• POST https://api.example.com/soap
• Body:
• <?xml version="1.0"?>
• <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
• <soap:Body>
• <GetUserRequest>
• <UserID>1’</UserID>
• </GetUserRequest>
• </soap:Body>
• </soap:Envelope>
GraphQL
• • Query language for APIs
• • Single endpoint
• • Fetch exactly what you need
• Example:
• POST https://api.example.com/graphql
• Query:
• { user(id: 1) { name email } }
• Response:
• { "data": { "user": { "name": "John Doe", "email": "
[email protected]" } } }
Anatomy of an API Request
• Example:
• GET https://api.example.com/users/1
• Headers:
• Authorization: Bearer <token>
• Content-Type: application/json
• Body: (for POST/PUT)
• { "name": "John Doe", "email": "[email protected]" }
• Patch https://api.example.com/users/1
• { "name": “nurul"}
Anatomy of an API Response
• Example:
• Status Code: 200 OK
• Headers:
• Content-Type: application/json
• Body:
• { "id": 1, "name": "John Doe", "email": "[email protected]" }
Common HTTP Methods
• GET /users -> Get all users
• POST /users -> Create a new user
• PUT /users/1 -> Replace user with ID 1
• PATCH /users/1 -> Update part of user with ID 1
• DELETE /users/1 -> Remove user with ID 1
• UPDATE
Demo – Postman
• Example: GET weather
• Endpoint:
• https://api.openweathermap.org/data/2.5/weather?
q=London&appid=YOUR_API_KEY
• Response:
• { "weather": [{ "main": "Clouds", "description": "scattered clouds" }], "name":
"London" }
Demo – curl
• • Example:
• • curl -X GET
"https://api.openweathermap.org/data/2.5/w
eather?q=London&appid=YOUR_API_KEY"
Assignment
• Try changing city names in query param
• Try units=metric or imperial
• Inspect status codes and headers
Summary
• • APIs are essential
• • Understand REST/SOAP/GraphQL
• • Postman and curl for testing
Q&A
• • Any questions?