0% found this document useful (0 votes)
94 views4 pages

API and GraphQL Exam Questions

The document contains graded questions and answers related to REST and GraphQL, covering topics such as API request methods, caching, and the characteristics of GraphQL. It highlights misconceptions about REST and GraphQL, the nature of HTTP requests, and the principles of headless CMS. The document also includes references for further reading on GraphQL and JSON.

Uploaded by

Ritu Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views4 pages

API and GraphQL Exam Questions

The document contains graded questions and answers related to REST and GraphQL, covering topics such as API request methods, caching, and the characteristics of GraphQL. It highlights misconceptions about REST and GraphQL, the nature of HTTP requests, and the principles of headless CMS. The document also includes references for further reading on GraphQL and JSON.

Uploaded by

Ritu Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Week 8 Graded Questions

Q1: Which of the following statements is false regarding REST and GraphQL?

A. In RESTful APIs, there are multiple endpoints to access different resources.


B. In GraphQL, there is only a single entry point in general.
C. GraphQL fixes the issue of over fetching the data.
D. Both REST API and GraphQL can request only a single resource with a single request.

Answer: D

Solution: GraphQL is a query language for our API, which helps to make complex queries and
helps to retrieve only the data that is required.
Ref: https://graphql.org/

Q2: Which of the following statement(s) is/are false regarding REST and GraphQL?

A. GraphQL can fetch the data from multiple sources and return the fused response.
B. In REST, the GET requests are not cacheable in general.
C. In GraphQL, the POST requests are cacheable in general.
D. GraphQL can execute a complex query to return a complex data set with a single
request, whereas, REST APIs may require to make multiple requests for the same.

Answer: B and C

Solution: A GraphQL query can be constructed, requesting data from multiple resources. A
request is generally cacheable, when the response can be constructed with just the URL, and
the reason for GET requests being cacheable is that a GET request has all the required data in
the URL. However, a POST request has data in the request body, which is not cacheable in
general.

Q3: Which of the following HTTP request methods is cacheable in general?

A. GET
B. POST
C. PUT
D. All of the above
Answer: A

Solution: A request is generally cacheable, when the response can be constructed with just
seeing the URL, and the reason for GET requests being cacheable is that a GET request has all
the required data in the URL. However, a POST or PUT request has data in the request body,
which is not cacheable in general.

Q4: Which of the following statements is true?

A. A POST GraphQL request with Content-Type header as “application/graphql” need not


always have the request body content as GraphQL query string.
B. A POST GraphQL request can also be made with a JSON body content.
C. The response to a GraphQL request is a JSON response, with the result stored in the
“data” field.
D. All of the above

Answer: B and C

Solution: A GraphQL request can be constructed with the “Content-Type” header value as both
“application/graphql” and “application/json”, but the body content should match with the header
value. The response to a GraphQL request is generally a JSON response, with the data stored
in “data” field.

Q5: Which of the following statements is/are false?

A. All the responses to the GraphQL requests should return 200 as the status code in
general.
B. A GET request cannot be made in GraphQL, and it must always send POST requests.
C. All the endpoints in a RESTful API should return 200 as the status code.
D. None of the above

Answer: B and C

Solution: An endpoint in an REST API should return an appropriate status code with the
response, and it need not be 200 always. You can read more about GraphQL at GraphQL -
GraphQL (dgraph.io)
Q6: Which of the following statement(s) is/are true?

A. Web Components allow us to create custom HTML elements.


B. HTML markup is more verbose than Markdown language.
C. Markdown content has inline styling in general.
D. A Web Component can have scoped styling.

Answer: A, B, C and D

Solution: A web component can be used to create custom HTML tags or elements (just the way
components in Vue work), and each of the web component can have styling specific to them,
which is not applied to other parts of the web page.
HTML is considered to be a more verbose language, if compared with Markdown, which has
inline styling in general.

Q7: Which of the following statement(s) is/are true about GraphQL?

A. Mutations in GraphQL can be used to change the underlying data store.


B. GraphQL services are created by defining types and fields of those types, then
providing functions for each field.
C. GraphQL can only fetch data from a single source.
D. GraphQL allows only GET operations.

Answer: A and B

Solution : In GraphQL query is used to retrieve information and mutations can be used to
change the underlying data store. The API’s in GraphQL are organized through types (entities)
and corresponding fields.
Reference : https://graphql.org/

Q8: Which of the following statement(s) is/are true regarding GraphQL?

A. It is a query language for APIs.


B. It is a client side runtime.
C. It is not tied to any specific database or storage engine.
D. It usually sends complex queries over the POST body of the HTTP request.

Answer: A, C and D
Solution: GraphQL is a query language for API. It can be thought of as a layer on the server
side through which we can make complex queries, usually over the POST body of the request.
It can connect to multiple data sources.

Q9: What is the main idea behind headless CMS?

A. The content repository is separated/decoupled from the presentation layer.


B. Content is delivered via APIs.
C. It helps in easier scalability.
D. A headless CMS cannot use REST APIs.

Answer: A, B and C

Solution: Headless CMS the content is decoupled from the front end. Content API can then be
used to access content where needed - website/mobile app.

Q10: Which of the following is the most commonly used representation for resources in
web APIs?

A. xml
B. json
C. webp
D. woff

Answer: B

Reference: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON

You might also like