0
0
Rest APIprogramming~10 mins

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

Choose your learning style9 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.