← Back to Chapters

Types of APIs

? Types of APIs

? Quick Overview

APIs (Application Programming Interfaces) allow different software systems to communicate with each other. The most commonly used API styles are REST, SOAP, and GraphQL. Each follows a different architectural approach and is suited for different use cases.

? Key Concepts

  • API – A contract that defines how software components interact
  • Client – Application requesting data
  • Server – Application providing data
  • Endpoint – URL that accepts requests
  • HTTP Methods – GET, POST, PUT, DELETE

? Syntax / Theory

? REST API

REST (Representational State Transfer) uses standard HTTP methods and works with resources identified by URLs. It is lightweight and typically uses JSON.

? SOAP API

SOAP (Simple Object Access Protocol) is a strict, XML-based protocol with built-in security and standards. It is commonly used in enterprise systems.

? GraphQL API

GraphQL allows clients to request exactly the data they need in a single request, reducing over-fetching and under-fetching of data.

? Code Example(s)

? View REST API Request (Postman / Fetch)
// REST API GET request using Fetch API
fetch("https://api.example.com/users")
.then(response => response.json())
.then(data => console.log(data));
? View SOAP API Request (XML)
// SOAP request body sent via HTTP
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<getUserDetails />
</soapenv:Body>
</soapenv:Envelope>
? View GraphQL Query
// GraphQL query requesting specific fields
query {
users {
id
name
email
}
}

? Live Output / Explanation

Expected Behavior

  • REST returns full JSON response from the endpoint
  • SOAP returns structured XML response
  • GraphQL returns only requested fields in JSON

? Interactive Example

Click the buttons below to simulate a request to a server. Observe the difference in how the request looks and how the data is returned.

➡️ Request Sent
Select a simulation above...
⬅️ Response Received
Waiting for input...

? Use Cases

  • REST – Web & mobile applications
  • SOAP – Banking, payment gateways, enterprise apps
  • GraphQL – Modern SPAs, mobile apps with complex data needs

? Tips & Best Practices

  • Use REST for simplicity and scalability
  • Choose SOAP when strict security and contracts are required
  • Use GraphQL to minimize network requests
  • Always document APIs clearly

? Try It Yourself

  1. Create a REST request in Postman
  2. Send a GraphQL query using Postman
  3. Compare response sizes
  4. Identify best API type for a given scenario