REST APIs and HTTP methods exam review

A comprehensive study set for understanding REST APIs and HTTP methods, focusing on key concepts, definitions, and practical applications in a college-level computer science context.

GraceDavis·36 flashcards·36 questions
collegecomputer_scienceweb
0
Known
1 / 36
0
Learning
Front

What does REST stand for?

Tap to flip
Back

Representational State Transfer.

Tap to flip
Got it
Still learning

Quiz(36 questions)

Question 1 of 36

1. What does the 'Client-Server' architecture in REST imply?

Terms in this Study Set(36)

REST API Basics(16)

What does REST stand for?

Representational State Transfer.

Define a REST API.

An application programming interface that conforms to the principles of REST.

True or False: REST APIs use stateful sessions.

False. REST APIs are stateless; each request from a client contains all information necessary.

List key principles of REST.

- Stateless - Client-Server architecture - Cacheable - Layered system - Uniform interface

What is statelessness in REST?

Each request must contain all data to complete the request, no session information is stored.

Fill in the blank: REST APIs typically use _____ for communication.

HTTP.

How does a REST API differ from a traditional API?

REST APIs use standard HTTP methods and are stateless, while traditional APIs may not.

What is a resource in REST?

An object or representation of something, usually identified by a URI.

True or False: REST APIs can only return JSON format.

False. They can return various formats, including XML and HTML.

Name an advantage of using REST APIs.

- Scalability - Flexibility - Simplicity of integration

Describe the Client-Server architecture in REST.

Client and server are separate; clients request resources and servers provide them without needing to know the client details.

What is a URI in REST?

A Uniform Resource Identifier that uniquely identifies a resource.

How does caching work in REST?

Responses are cacheable to improve performance and reduce server load.

What does the uniform interface principle enforce?

Consistent and standardized communication between clients and servers.

Example of a RESTful resource retrieval.

GET /users/1 retrieves the user with ID 1.

What is HATEOAS?

Hypermedia as the Engine of Application State; clients interact dynamically with applications through hyperlinks.

HTTP Methods(20)

GET method → primary use?

Retrieve data from the server. - Safe operation - Idempotent

What does POST do?

Creates a new resource on the server. Sends data in the request body.

True or False: GET requests can change server data.

False. GET requests should never modify data as they are intended for retrieval.

Difference between PUT and PATCH?

PUT updates/creates a resource fully. PATCH updates a resource partially.

DELETE method → purpose?

Removes a resource from the server. - Idempotent - Can affect state

Fill in the blank: PUT is used to _____ a resource.

update or create

Example of a GET request?

GET /api/users/123 - Retrieves user data for user with ID 123.

When to use POST instead of GET?

Use POST when submitting data that changes state, like creating users.

What does the DELETE method return?

Usually returns a status code like 204 (No Content) if successful.

True or False: POST is idempotent.

False. Multiple POST requests may create multiple resources.

GET vs POST: Which one is cached?

GET requests can be cached, while POST requests are typically not cached.

Use case for PATCH method?

To update a user's email without affecting other user data.

What status code does a successful DELETE return?

204 No Content or 200 OK depending on the API design.

GET request with parameters example?

GET /api/products?category=shoes - Retrieves products in the shoes category.

Main difference between PUT and POST?

PUT is idempotent; POST creates resources without guaranteeing uniqueness.

True or False: Sending a GET request with sensitive data is safe.

False. GET data is visible in URLs and logs, making it insecure.

What does status code 201 indicate?

Created: Indicates a successful POST request that created a resource.

Purpose of OPTIONS method?

Describes the communication options for the target resource.

Example of a PUT request?

PUT /api/users/123 - Updates user data for user with ID 123.

Use case for DELETE method?

To remove a user from a database.

Questions in this Study Set(36)

1. What does the 'Client-Server' architecture in REST imply?

A.Clients and servers operate independently.
B.Clients and servers are tightly coupled.
C.The client handles data storage.
D.Servers manage client sessions.

2. What is the primary purpose of the GET method?

A.Retrieve data from the server
B.Create a new resource
C.Update an existing resource
D.Remove a resource

3. Which HTTP method is primarily used to retrieve data from a REST API?

A.POST
B.GET
C.PUT
D.DELETE

4. Which HTTP method is used to create a new resource on the server?

A.PUT
B.DELETE
C.POST
D.GET

5. True or False: REST APIs are designed to be stateful.

A.True
B.False
C.Only during data retrieval
D.Only during data submission

6. True or False: Using GET requests can modify server data.

A.True
B.False
C.Depends on the server
D.Never

7. Which of the following is NOT a key principle of REST?

A.Statelessness
B.Client-Server architecture
C.Layered system
D.Session-based interaction

8. What distinguishes PUT from PATCH?

A.PUT creates a resource, while PATCH updates it
B.PATCH creates a resource, while PUT deletes it
C.PUT updates a resource fully, PATCH updates partially
D.PUT is safer than PATCH

9. What is the primary function of a URI in a REST API?

A.To provide data format
B.To uniquely identify a resource
C.To manage server load
D.To define encryption methods

10. What is the primary action of the DELETE method?

A.Retrieve a resource
B.Remove a resource
C.Update a resource
D.Create a resource

11. Fill in the blank: REST APIs usually respond in _____ format.

A.CSV
B.JSON
C.SOAP
D.FTP

12. Fill in the blank: PUT is used to _____ a resource.

A.delete
B.update or create
C.retrieve
D.ignore

13. What does it mean for a REST API to be cacheable?

A.Responses can be stored for future use.
B.Clients must resend all requests.
C.APIs must always return fresh data.
D.Data is encrypted before caching.

14. What is an example of a valid GET request?

A.POST /api/users
B.GET /api/users/123
C.DELETE /api/users/123
D.PUT /api/products

15. Which of the following methods is used to update an existing resource in a REST API?

A.POST
B.GET
C.PUT
D.DELETE

16. When should you use POST instead of GET?

A.When retrieving data
B.When modifying state or creating resources
C.When deleting data
D.When updating resources

17. Which statement best describes HATEOAS?

A.It restricts client interactions to a fixed set of actions.
B.Clients navigate an API using links provided in responses.
C.It is only applicable to XML responses.
D.It ensures that all resources are stored on the server.

18. What does a successful DELETE method typically return?

A.200 OK
B.204 No Content
C.201 Created
D.400 Bad Request

19. Which HTTP method is used to delete a resource in a REST API?

A.GET
B.POST
C.PUT
D.DELETE

20. True or False: POST is considered an idempotent method.

A.True
B.False
C.Only in some cases
D.Not applicable

21. True or False: REST APIs can only communicate over HTTPS.

A.True
B.False
C.Only for sensitive data
D.Only with certain clients

22. Which HTTP method can be cached by default?

A.POST
B.PUT
C.DELETE
D.GET

23. Which of the following best describes the uniform interface principle in REST?

A.It allows different data formats.
B.It standardizes how clients and servers communicate.
C.It requires all clients to be identical.
D.It restricts API access to certain IP addresses.

24. What is a common use case for the PATCH method?

A.To create a new user
B.To remove a user
C.To update a user's email
D.To retrieve user data

25. In REST, which HTTP method is used primarily for creating new resources?

A.GET
B.POST
C.PUT
D.PATCH

26. What status code indicates that a resource was successfully created?

A.200 OK
B.404 Not Found
C.201 Created
D.500 Internal Server Error

27. What does REST focus on in terms of resource representation?

A.Only JSON format
B.Stateful sessions
C.Interoperability between systems
D.Static data presentation

28. What does the OPTIONS method do?

A.Retrieves resource data
B.Describes communication options for the target resource
C.Creates a new resource
D.Deletes a resource

29. What does RESTful architecture emphasize in its communication between client and server?

A.Statelessness
B.Stateful sessions
C.Synchronous communication
D.Binary protocols

30. What is an example of a valid PUT request?

A.GET /api/users
B.PUT /api/users/123
C.POST /api/products
D.DELETE /api/orders

31. Which of the following best defines a resource in the context of REST?

A.A specific API endpoint
B.An object or data representation identified by a URI
C.The server where the API is hosted
D.An HTTP method used for requests

32. In what scenario would you use the DELETE method?

A.To update user information
B.To create a new order
C.To remove a product from a database
D.To retrieve product details

33. Which of the following is NOT a primary HTTP method?

A.GET
B.POST
C.CONNECT
D.UPDATE

34. True or False: GET requests can safely include sensitive data in the URL.

A.True
B.False
C.Only in local environments
D.Depends on the application

35. What is the result of sending a valid PATCH request?

A.It creates a new resource
B.It updates part of an existing resource
C.It deletes a resource
D.It fetches resource data

36. Which HTTP method is primarily used to partially update a resource?

A.PATCH
B.PUT
C.POST
D.DELETE

Related Study Sets

Create Your Own Study Set

Upload a PDF, paste your notes, or describe a topic – AI generates flashcards, quizzes and more in seconds.