POC POC Web Development & APIs 2 — Questions and Answers
Question 1: What is JSON and why is it preferred for web API data exchange?
- A lightweight, human-readable text format easy to parse in any language (Correct answer)
- A Python-specific binary format for fast web responses
- A SQL-based encoding format for structured data
- A type of database query language for APIs
Correct answer: A lightweight, human-readable text format easy to parse in any language
JSON (JavaScript Object Notation) is a lightweight, human-readable data interchange format supported natively in virtually every programming language.
Question 2: Which HTTP method is used to retrieve data from a server without modifying state?
- GET (Correct answer)
- POST
- PUT
- PATCH
Correct answer: GET
The GET method requests a representation of the specified resource and must not have side effects on server state.
Question 3: In Python's `requests` library, how do you pass query string parameters in a GET request?
- Using the `params` keyword argument with a dictionary (Correct answer)
- Appending them manually to the URL string
- Using the `query` keyword argument
- Using the `args` keyword argument
Correct answer: Using the `params` keyword argument with a dictionary
The `params` keyword in `requests.get()` accepts a dict that gets URL-encoded and appended automatically as the query string.
Question 4: What does Flask's `jsonify()` function do?
- Converts Python data to a JSON HTTP Response with correct Content-Type (Correct answer)
- Parses incoming JSON request bodies
- Validates request data against a JSON schema
- Formats JSON data for application logging
Correct answer: Converts Python data to a JSON HTTP Response with correct Content-Type
Flask's `jsonify()` serializes Python data to JSON and returns a Response with `Content-Type: application/json` automatically set.
Question 5: What HTTP status code is returned when a requested resource cannot be found?
- 404 (Correct answer)
- 200
- 500
- 403
Correct answer: 404
HTTP 404 (Not Found) indicates the server could not locate the requested resource at the given URL.
Question 6: What is an API endpoint?
- A specific URL where a resource can be accessed to perform an operation (Correct answer)
- The backend server that processes all API requests
- The authentication token required for API access
- The interactive documentation page for an API
Correct answer: A specific URL where a resource can be accessed to perform an operation
An API endpoint is a specific URL that represents a resource or collection, defining where clients can interact with that resource.
What is JSON and why is it preferred for web API data exchange?