Quiz: Module 04: APIs and Programming
Test your understanding of the concepts covered in this module.
50 questions · 0/50 answered
Question 1. Which of the following best describes what an API (Application Programming Interface) is?
Question 2. True or False: REST APIs use standard HTTP methods such as GET, POST, PUT, and DELETE to perform actions on resources.
Question 3. Which HTTP method is used to retrieve data from a REST API without modifying anything on the server?
Question 4. In your own words, explain what a REST API endpoint is and give an example of what one might look like.
Free-response questions are self-assessed. Compare your answer with the sample response.
Question 5. A developer sends a request to `https://api.example.com/products/42`. In REST API terminology, what does `/products/42` represent?
Question 6. Which HTTP method would you use to create a new user account through a REST API?
Question 7. True or False: The HTTP PUT method is typically used to update an existing resource on the server.
Question 8. Which of the following is valid JSON?
Question 9. In JSON, which of the following are valid value types? (Select THREE.)Select multiple
Question 10. What is wrong with the following JSON? ```json { "name": "Bob", "age": 30, "active": true, } ```
Question 11. Which of the following correctly represents a JSON array?
Question 12. True or False: In JSON, keys must always be strings enclosed in double quotes.
Question 13. Given the following JSON, what is the value of `"city"`? ```json { "name": "Alice", "address": { "city": "Seattle", "state": "WA" } } ```
Question 14. What is the purpose of an API key?
Question 15. True or False: An API key should be kept secret and never shared publicly in your code or version control.
Question 16. Which of the following best describes an authentication token (such as a bearer token) in the context of APIs?
Question 17. A developer receives an HTTP `401 Unauthorized` response from an API. What is the most likely cause?
Question 18. Which HTTP status code range indicates that the request was successful?
Question 19. A REST API returns a `404 Not Found` status code. What does this mean?
Question 20. In your own words, explain the difference between an API key and an authentication token.
Free-response questions are self-assessed. Compare your answer with the sample response.
Question 21. What is a variable in programming?
Question 22. Which of the following Python code correctly assigns the string `"hello"` to a variable named `greeting`?
Question 23. Match each value to its data type: | Value | Data Type | |-------|-----------| | `"Seattle"` | _______ | | `42` | _______ | | `3.14` | _______ | | `True` | _______ | | `["a", "b", "c"]` | _______ | Choose from: String, Integer, Float, Boolean, List/Array
Free-response questions are self-assessed. Compare your answer with the sample response.
Question 24. True or False: In Python, the boolean value `True` must be capitalized (uppercase T), while in JavaScript it is written as `true` (lowercase t).
Question 25. Which of the following is a dictionary (key-value pair collection) in Python?
Question 26. What is a function in programming?
Question 27. What will the following Python function return when called with `calculate_total(5, 3)`? ```python def calculate_total(price, quantity): return price * quantity ```
Question 28. True or False: A function can accept inputs (called parameters or arguments) and return an output value.
Question 29. Which of the following correctly defines a function in Python that takes two parameters?
Question 30. In JavaScript, which of the following correctly defines a function?
Question 31. What does the following Python code print? ```python temperature = 75 if temperature > 80: print("Hot") elif temperature > 60: print("Warm") else: print("Cool") ```
Question 32. True or False: In an if/elif/else chain, only the first branch whose condition is true will execute; the remaining branches are skipped.
Question 33. What will the following JavaScript code output? ```javascript let score = 85; if (score >= 90) { console.log("A"); } else if (score >= 80) { console.log("B"); } else { console.log("C"); } ```
Question 34. Which of the following best describes the purpose of an `else` block in a conditional statement?
Question 35. How many times will the following Python loop print a message? ```python fruits = ["apple", "banana", "cherry"] for fruit in fruits: print(fruit) ```
Question 36. What is the key difference between a `for` loop and a `while` loop?
Question 37. What will the following Python code print? ```python count = 0 while count < 3: print(count) count = count + 1 ```
Question 38. True or False: If the condition in a `while` loop never becomes false, the loop will run indefinitely (an infinite loop).
Question 39. What will the following JavaScript code output? ```javascript for (let i = 0; i < 4; i++) { console.log(i); } ```
Question 40. In Python, what does the `len()` function do when called on a list?
Question 41. Which of the following Python code snippets correctly loops through a dictionary and prints each key?
Question 42. A developer is reading API documentation and sees the following endpoint description: ``` GET /api/v1/users/{id} ``` What does `{id}` represent?
Question 43. True or False: Good API documentation typically includes the available endpoints, required parameters, expected response format, and authentication requirements.
Question 44. A REST API documentation page shows the following: ``` POST /api/v1/orders Content-Type: application/json Authorization: Bearer <token> { "product_id": 101, "quantity": 2 } ``` Which of the following statements are true about this request? (Select TWO.)Select multiple
Question 45. What does the `Content-Type: application/json` header tell the server?
Question 46. In your own words, describe what happens when a program makes a REST API call and receives a JSON response. Include the role of the HTTP method, the endpoint, and the response format.
Free-response questions are self-assessed. Compare your answer with the sample response.
Question 47. What will the following Python code print? ```python data = {"name": "Alice", "scores": [90, 85, 92]} print(data["scores"][1]) ```
Question 48. Which of the following is NOT a common HTTP method used in REST APIs?
Question 49. A developer writes the following Python code. What will it print? ```python numbers = [10, 20, 30, 40, 50] total = 0 for num in numbers: total = total + num print(total) ```
Question 50. True or False: JSON and Python dictionaries look similar, but JSON is a text-based data format used for exchanging data between systems, while a Python dictionary is a data structure that exists in memory during program execution.