Bird
Raised Fist0
Rest APIprogramming~20 mins

REST vs SOAP vs GraphQL comparison in Rest API - Practice Questions

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
API Mastery: REST, SOAP & GraphQL
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Key difference in data fetching between REST and GraphQL
Which statement best describes how REST and GraphQL differ in data fetching?
AREST allows clients to specify exactly what data they want, GraphQL fetches fixed data per endpoint.
BREST fetches fixed data per endpoint, GraphQL allows clients to specify exactly what data they want.
CBoth REST and GraphQL always fetch all data from the server regardless of client request.
DREST and GraphQL both require multiple requests to fetch related data.
Attempts:
2 left
💡 Hint
Think about how flexible the client is in choosing data with each approach.
❓ Predict Output
intermediate
2:00remaining
Output of a SOAP fault response
What is the output when a SOAP service returns a fault response with this XML snippet?
Rest API
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <soap:Fault>
      <faultcode>soap:Client</faultcode>
      <faultstring>Invalid request</faultstring>
    </soap:Fault>
  </soap:Body>
</soap:Envelope>
AA timeout error from the server.
BA successful response with requested data.
CA syntax error in the SOAP message.
DAn error indicating 'Invalid request' with fault code 'soap:Client'.
Attempts:
2 left
💡 Hint
Look at the element and its children.
❓ Predict Output
advanced
2:00remaining
GraphQL query result for nested data
Given this GraphQL query, what is the expected JSON response?
Rest API
query {
  user(id: "1") {
    name
    posts {
      title
      comments {
        text
      }
    }
  }
}
A{ "data": { "user": { "name": "Alice", "posts": [ { "title": "Hello", "comments": [ { "text": "Nice post!" } ] } ] } } }
B{ "data": { "user": { "name": "Alice" } } }
C{ "error": "Field 'posts' not found" }
D{ "data": { "user": null } }
Attempts:
2 left
💡 Hint
GraphQL returns exactly the fields requested, including nested objects.
🧠 Conceptual
advanced
2:00remaining
SOAP vs REST protocol characteristics
Which of these is true about SOAP compared to REST?
ASOAP is stateless and uses JSON only, REST is stateful and uses XML only.
BSOAP is simpler and faster than REST for all use cases.
CSOAP uses XML and has built-in standards for security and transactions, REST is more flexible and uses multiple formats.
DSOAP does not support encryption, REST always requires encryption.
Attempts:
2 left
💡 Hint
Think about the protocol and message format differences.
🧠 Conceptual
expert
2:00remaining
Choosing API style for complex client-driven data needs
A mobile app needs to fetch complex, nested data but wants to minimize the number of requests and data size. Which API style is best suited?
AGraphQL, because it allows clients to request exactly the nested data they need in one request.
BSOAP, because it uses XML which is smaller and faster than JSON.
CREST, because it requires multiple endpoints and requests for nested data.
DNone, because all API styles require multiple requests for nested data.
Attempts:
2 left
💡 Hint
Consider how each API style handles nested data and request flexibility.

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