REST, GraphQL, and gRPC: Core Differences Quiz Quiz

Challenge your understanding of the fundamental differences between REST, GraphQL, and gRPC protocols. Explore key concepts, use cases, and technical distinctions to elevate your API architecture knowledge.

  1. Protocol Paradigms

    Which of the following communication protocols is primarily based on the HTTP/1.1 standard and uses resources identified by URLs?

    1. GraphQL
    2. gRPC
    3. RPC
    4. REST

    Explanation: REST is fundamentally built on top of the HTTP/1.1 protocol and heavily utilizes URLs to represent resources. GraphQL is a query language that can operate over HTTP but does not directly rely on URLs as REST does. gRPC primarily uses HTTP/2 and protocol buffers, not basic HTTP/1.1. RPC is a broader concept and not tied to HTTP/1.1 or URLs directly.

  2. Request Flexibility

    If a client wants to request only specific fields from an object in a single API call, which API design approach would be most suitable?

    1. gRPC
    2. REST
    3. GraphQL
    4. SOAP

    Explanation: GraphQL allows clients to request exactly the data they need by specifying fields in their queries, which minimizes over-fetching or under-fetching. REST typically returns pre-defined data structures, so clients can't always choose specific fields. gRPC uses strict contracts with protocol buffers, and SOAP is based on XML and WSDL, not designed for flexible field selection.

  3. Data Serialization

    Which protocol most commonly uses protocol buffers for serializing structured data between client and server?

    1. gPRC
    2. REST
    3. gRPC
    4. GraphQL

    Explanation: gRPC relies on protocol buffers to serialize and deserialize messages, enabling fast and efficient communication. REST typically uses JSON or XML rather than protocol buffers. GraphQL uses JSON for responses. The option 'gPRC' is a typo and not an actual protocol.

  4. Transport Layer Differences

    Which approach primarily uses HTTP/2 as its underlying transport layer for improved performance and supports multiplexed streams?

    1. REST
    2. gRPC
    3. FTP
    4. GraphQL

    Explanation: gRPC is designed to work with HTTP/2, taking advantage of features like multiplexed streams and header compression for enhanced performance. REST and GraphQL generally use HTTP/1.1, and FTP is not an API protocol but a file transfer protocol.

  5. Error Handling Conventions

    In which API style are errors typically conveyed using standard HTTP status codes such as 404 or 500?

    1. GraphQL
    2. REST
    3. gRPC
    4. RPC

    Explanation: REST APIs conventionally use HTTP status codes to indicate the result of requests, such as 404 for not found or 500 for server errors. gRPC uses its own set of status codes. GraphQL usually includes error messages within the response payload. RPC is a general term, and not tied to HTTP error codes by default.

  6. Batch and Streaming Support

    Which protocol natively supports bidirectional streaming of data between client and server?

    1. SOAP
    2. gRPC
    3. GraphQL
    4. REST

    Explanation: gRPC offers native support for bidirectional streaming, enabling real-time, two-way communication between client and server. REST is typically request-response based and does not support streaming out of the box. GraphQL supports subscription-based updates but not full bidirectional streams. SOAP is designed for message-based communication, not streaming.

  7. Schema and Type Enforcement

    Which of these protocols requires a strongly typed contract, often specified in a '.proto' file, for message structure?

    1. REST
    2. GRQL
    3. GraphQL
    4. gRPC

    Explanation: gRPC relies on strongly typed contracts defined in '.proto' files for message format and service interfaces. REST typically uses loosely structured formats like JSON, and GraphQL defines its schema in its own schema definition language, not a '.proto' file. 'GRQL' is not a valid protocol and is listed as a distractor.

  8. Data Fetching Approaches

    A client is frustrated by having to make multiple network requests to retrieve related resources. Which API style best addresses this problem by allowing multiple resources to be fetched in one request?

    1. gRPC
    2. GraphQL
    3. REST
    4. SOAP

    Explanation: GraphQL enables clients to request nested or multiple resources in a single query, solving the 'multiple round trips' issue common in REST. REST usually requires separate requests for each resource unless custom endpoints are implemented. gRPC is efficient but doesn't natively solve over-fetching or under-fetching for complex, related data. SOAP is verbose and not optimized for flexible bulk fetching.

  9. Use Case Fit

    For an environment with many microservices needing efficient, low-latency, machine-to-machine communication, which protocol is usually preferred?

    1. REST
    2. gRPC
    3. SMTP
    4. GraphQL

    Explanation: gRPC is optimized for microservices architectures requiring fast, efficient binary communication thanks to protocol buffers and HTTP/2. REST is widely used but is text-based and can be less efficient between services. GraphQL is powerful for flexible queries but not always the fastest choice for internal service communication. SMTP is an email protocol, irrelevant to API service communication.

  10. Versioning Practices

    Which API style often requires explicit versioning in the endpoint URL to handle breaking changes, such as '/api/v2/items'?

    1. GraphQL
    2. REST
    3. gRPC
    4. SOAP

    Explanation: REST APIs frequently manage breaking changes by updating the version in the endpoint URL. gRPC handles changes through versioned '.proto' files but not through URL paths. GraphQL typically uses a single endpoint and might version schemas internally. SOAP is not commonly versioned via URLs but rather through namespaces.