0% found this document useful (0 votes)
33 views15 pages

Intro To APIs With Examples

The document provides an introduction to APIs, explaining their definition, importance, and types including REST, SOAP, and GraphQL. It details the anatomy of API requests and responses, common HTTP methods, and includes examples of using Postman and curl for testing APIs. The document concludes with a summary emphasizing the necessity of understanding APIs and their testing tools.

Uploaded by

neral92027
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views15 pages

Intro To APIs With Examples

The document provides an introduction to APIs, explaining their definition, importance, and types including REST, SOAP, and GraphQL. It details the anatomy of API requests and responses, common HTTP methods, and includes examples of using Postman and curl for testing APIs. The document concludes with a summary emphasizing the necessity of understanding APIs and their testing tools.

Uploaded by

neral92027
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

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?

You might also like