Bird
Raised Fist0
Rest APIprogramming~10 mins

REST vs SOAP vs GraphQL comparison in Rest API - Visual Side-by-Side Comparison

Choose your learning style10 modes available
Concept Flow - REST vs SOAP vs GraphQL comparison
Client sends request
↓
REST
↓
Uses HTTP
↓
Stateless
↓
Resource
↓
URLs
↓
JSON/XML
↓
Multiple
↓
Endpoints
↓
Cache
↓
Client receives response
Client sends a request, chooses REST, SOAP, or GraphQL, each with different protocols and data formats, then receives a response.
Execution Sample
Rest API
GET /users/123 HTTP/1.1
Host: api.example.com

--- REST example

POST /soap HTTP/1.1
Host: api.example.com
Content-Type: text/xml

<soapenv:Envelope>...</soapenv:Envelope>

--- SOAP example

POST /graphql HTTP/1.1
Host: api.example.com
Content-Type: application/json

{"query": "{ user(id: \"123\") { name } }"}

--- GraphQL example
Shows example requests for REST, SOAP, and GraphQL APIs fetching user data.
Execution Table
StepAPI TypeRequest SentData FormatResponse ReceivedNotes
1RESTGET /users/123JSON or XMLUser data in JSONSimple URL, stateless
2SOAPPOST /soap with XML envelopeXMLUser data in XMLStrict protocol, built-in security
3GraphQLPOST /graphql with query JSONJSONUser data shaped by querySingle endpoint, flexible data
4RESTGET /users/123JSON or XML404 Not Found if user missingStandard HTTP status codes
5SOAPPOST /soap with XML envelopeXMLSOAP Fault messageStandardized error handling
6GraphQLPOST /graphql with query JSONJSONErrors in response bodyErrors returned in data structure
7RESTGET /usersJSON or XMLList of usersMultiple endpoints for resources
8SOAPPOST /soap with XML envelopeXMLResponse with multiple dataComplex operations supported
9GraphQLPOST /graphql with query JSONJSONCustom shaped list of usersClient controls data shape
10Exit---All requests processed
💡 All API types processed their requests and returned responses or errors.
Variable Tracker
VariableStartAfter RESTAfter SOAPAfter GraphQLFinal
Request TypeNoneGET /users/123POST /soap XMLPOST /graphql JSONCompleted
Data FormatNoneJSON/XMLXMLJSONCompleted
ResponseNoneUser JSONUser XMLUser JSON shapedCompleted
Error HandlingNoneHTTP statusSOAP FaultErrors in JSONCompleted
Key Moments - 3 Insights
Why does SOAP always use XML while REST can use JSON or XML?
SOAP is a protocol that requires XML envelopes for messages (see execution_table rows 2 and 5). REST is more flexible and can use JSON or XML depending on the API design (rows 1 and 4).
How does GraphQL let clients control the data shape?
GraphQL uses queries sent in JSON that specify exactly what fields are needed (execution_table row 3 and 9). This means clients get only the data they ask for, unlike REST or SOAP.
Why does REST use multiple endpoints but GraphQL uses a single endpoint?
REST maps resources to URLs (execution_table rows 1 and 7), so each resource has its own endpoint. GraphQL uses one endpoint and clients specify queries to get different data shapes (rows 3 and 9).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what data format does SOAP use in its requests?
APlain text
BJSON
CXML
DYAML
💡 Hint
Check the 'Data Format' column for SOAP rows (2 and 5) in the execution table.
At which step does GraphQL return errors inside the response body?
AStep 6
BStep 9
CStep 3
DStep 2
💡 Hint
Look for 'Errors in response body' in the 'Notes' column for GraphQL in the execution table.
If REST used a single endpoint like GraphQL, what would change in the execution table?
ASOAP would stop using XML
BMultiple endpoints rows would merge into one
CGraphQL would use multiple endpoints
DError handling would change
💡 Hint
Refer to the 'Notes' column about endpoints in REST and GraphQL rows.
Concept Snapshot
REST, SOAP, and GraphQL are ways to build APIs.
REST uses multiple URLs and supports JSON or XML.
SOAP uses XML with strict rules and built-in security.
GraphQL uses one endpoint and lets clients ask for exactly what they want.
REST is simple and cacheable; SOAP is strict and secure; GraphQL is flexible but complex.
Full Transcript
This visual compares REST, SOAP, and GraphQL APIs. The client sends a request choosing one API type. REST uses HTTP methods and multiple URLs, returning JSON or XML. SOAP sends XML envelopes with strict rules and built-in security. GraphQL uses a single HTTP endpoint with JSON queries that specify exactly what data the client wants. The execution table shows example requests and responses for each API type, including how errors are handled. Variables track request types, data formats, responses, and error handling across the three APIs. Key moments clarify why SOAP uses XML, how GraphQL controls data shape, and why REST uses multiple endpoints. The quiz tests understanding of data formats, error handling, and endpoint differences. The snapshot summarizes the main differences simply and clearly.

Practice

(1/5)
1. Which API style allows clients to request exactly the data they need in a single query?
easy
A. FTP
B. REST
C. SOAP
D. GraphQL

Solution

  1. Step 1: Understand GraphQL's data fetching

    GraphQL lets clients specify exactly which fields they want in a query, reducing over-fetching.
  2. Step 2: Compare with REST and SOAP

    REST uses fixed endpoints and HTTP methods, SOAP uses strict XML messages, neither allows flexible data selection like GraphQL.
  3. Final Answer:

    GraphQL -> Option D
  4. Quick Check:

    Exact data request = GraphQL [OK]
Hint: GraphQL = precise data queries in one request [OK]
Common Mistakes:
  • Confusing REST with GraphQL's flexible queries
  • Thinking SOAP supports flexible data selection
  • Choosing unrelated protocols like FTP
2. Which of the following is the correct HTTP method typically used by REST APIs to update a resource?
easy
A. PUT
B. POST
C. GET
D. CONNECT

Solution

  1. Step 1: Recall REST HTTP methods

    REST commonly uses PUT to update or replace a resource at a URL.
  2. Step 2: Differentiate from other methods

    GET retrieves data, POST creates new resources, CONNECT is for network tunnels, so only PUT updates.
  3. Final Answer:

    PUT -> Option A
  4. Quick Check:

    Update resource = PUT [OK]
Hint: PUT method updates resources in REST [OK]
Common Mistakes:
  • Using GET to update data
  • Confusing POST with update instead of create
  • Selecting non-REST HTTP methods like CONNECT
3. Given the following GraphQL query, what data will the client receive?
{ user(id: "123") { name email } }
medium
A. {"user": {"name": "Alice"}}
B. {"user": {"name": "Alice", "email": "alice@example.com"}}
C. {"user": {"id": "123", "name": "Alice"}}
D. {"user": {"email": "alice@example.com"}}

Solution

  1. Step 1: Analyze the GraphQL query fields

    The query requests the user's name and email fields for user with id "123".
  2. Step 2: Determine expected response

    The response includes both requested fields inside the user object, matching {"user": {"name": "Alice", "email": "alice@example.com"}}.
  3. Final Answer:

    {"user": {"name": "Alice", "email": "alice@example.com"}} -> Option B
  4. Quick Check:

    Requested fields = name and email [OK]
Hint: GraphQL returns only requested fields in response [OK]
Common Mistakes:
  • Expecting all user fields returned
  • Missing one of the requested fields
  • Confusing id field presence
4. You have a SOAP API call that fails due to incorrect message format. What is the most likely cause?
medium
A. Using GraphQL query syntax in the request
B. Missing HTTP GET method in the request
C. Using JSON instead of XML in the request body
D. Not specifying the resource URL correctly

Solution

  1. Step 1: Understand SOAP message format requirements

    SOAP requires XML formatted messages strictly following its schema.
  2. Step 2: Identify common format errors

    Sending JSON instead of XML breaks the SOAP message format, causing failure.
  3. Final Answer:

    Using JSON instead of XML in the request body -> Option C
  4. Quick Check:

    SOAP needs XML, not JSON [OK]
Hint: SOAP messages must be XML formatted [OK]
Common Mistakes:
  • Using JSON payloads with SOAP
  • Confusing HTTP methods for SOAP
  • Mixing GraphQL syntax with SOAP
5. You need to design an API for a mobile app that requires minimal data usage and flexible queries. Which API style is best and why?
hard
A. GraphQL, because it lets clients request exactly the data they need
B. REST, because it uses simple URLs and HTTP methods
C. SOAP, because it uses strict XML for secure communication
D. FTP, because it transfers files efficiently

Solution

  1. Step 1: Identify requirements for minimal data and flexible queries

    The app needs to reduce data usage and allow clients to specify data fields.
  2. Step 2: Match API styles to requirements

    GraphQL allows clients to request only needed data in one query, minimizing data transfer and providing flexibility.
  3. Final Answer:

    GraphQL, because it lets clients request exactly the data they need -> Option A
  4. Quick Check:

    Minimal data + flexible queries = GraphQL [OK]
Hint: Choose GraphQL for flexible, minimal data queries [OK]
Common Mistakes:
  • Choosing REST without flexible data selection
  • Selecting SOAP despite heavy XML overhead
  • Confusing FTP with API styles
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard