Web Programming Web APIs and REST 2 — Questions and Answers
Question 1: Which HTTP method is idempotent and used to fully replace a resource?
- POST
- PATCH
- PUT (Correct answer)
- DELETE
Correct answer: PUT
PUT is idempotent and replaces the entire target resource with the supplied data, unlike PATCH which only applies partial modifications.
Question 2: What is an API endpoint?
- The server's IP address
- A specific URL where an API can be accessed to perform a function (Correct answer)
- The last line of an API file
- A type of API authentication
Correct answer: A specific URL where an API can be accessed to perform a function
An API endpoint is a specific URL that represents a resource or action, acting as the access point where an API receives requests and sends responses.
Question 3: What HTTP status code means 'Not Found'?
- 401
- 403
- 500
- 404 (Correct answer)
Correct answer: 404
HTTP 404 Not Found indicates that the server cannot find the requested resource at the given URL.
Question 4: What is the purpose of an API key?
- To encrypt all API data
- To authenticate and identify the calling application or user (Correct answer)
- To specify the API version
- To compress API responses
Correct answer: To authenticate and identify the calling application or user
An API key is a unique identifier used to authenticate and track API requests, allowing the server to identify and authorize the calling application.
Question 5: Which JavaScript API is used to make HTTP requests from the browser?
- XMLHttpRequest only
- fetch() (Correct answer)
- http.request()
- axios (built-in)
Correct answer: fetch()
The Fetch API provides a modern, Promise-based interface for making HTTP requests from the browser, replacing the older XMLHttpRequest.
Question 6: What does HTTP status code 401 indicate?
- Resource not found
- Server error
- Unauthorized — authentication required (Correct answer)
- Forbidden — access denied
Correct answer: Unauthorized — authentication required
HTTP 401 Unauthorized indicates that the request lacks valid authentication credentials and the client must authenticate to get the requested response.
Which HTTP method is idempotent and used to fully replace a resource?