Programming MCQs Feed

📊 Trishul API
Q. Which method can modify response headers?
  • (A) handle_request()
  • (B) handle_response()
  • (C) Both
  • (D) None
💬 Discuss
✅ Correct Answer: (B) handle_response()

Explanation: Response headers are modified in handle_response().

📊 Trishul API
Q. Should middleware terminate execution?
  • (A) Always
  • (B) Never
  • (C) Only when necessary (e.g., security)
  • (D) Only for logging
💬 Discuss
✅ Correct Answer: (C) Only when necessary (e.g., security)

Explanation: Docs say avoid termination unless necessary.

📊 Trishul API
Q. Which use case is NOT suitable for middleware?
  • (A) Authentication
  • (B) Logging
  • (C) UI rendering
  • (D) CORS handling
💬 Discuss
✅ Correct Answer: (C) UI rendering

Explanation: Middleware is backend processing, not UI.

📊 Trishul API
Q. What can middleware modify?
  • (A) Only request
  • (B) Only response
  • (C) Both request and response
  • (D) Database schema
💬 Discuss
✅ Correct Answer: (C) Both request and response

Explanation: Middleware can modify both.

📊 Trishul API
Q. Which class is used in handle_request() parameter?
  • (A) Response
  • (B) Request
  • (C) Router
  • (D) DB
💬 Discuss
✅ Correct Answer: (B) Request

Explanation: Receives Request object.

📊 Trishul API
Q. Which class is used in handle_response() parameter?
  • (A) Request
  • (B) Router
  • (C) Response
  • (D) Model
💬 Discuss
✅ Correct Answer: (C) Response

Explanation: Receives Response object.

📊 Trishul API
Q. What is a key rule when implementing middleware?
  • (A) Always return null
  • (B) Always return Request/Response object
  • (C) Always throw exception
  • (D) Always log data
💬 Discuss
✅ Correct Answer: (B) Always return Request/Response object

Explanation: Returning objects is mandatory.

📊 Trishul API
Q. Which scenario may justify stopping execution in middleware?
  • (A) Logging info
  • (B) Authentication failure
  • (C) Adding headers
  • (D) Formatting response
💬 Discuss
✅ Correct Answer: (B) Authentication failure

Explanation: Security reasons like auth failure can stop execution.

📊 Trishul API
Q. What is the primary responsibility of the DB class?
  • (A) Routing requests
  • (B) Providing database connection
  • (C) Handling middleware
  • (D) Managing API responses
💬 Discuss
✅ Correct Answer: (B) Providing database connection

Explanation: DB class provides PDO database connection.

📊 Trishul API
Q. Which design pattern is used by DB::get_connection()?
  • (A) Factory
  • (B) Singleton
  • (C) Observer
  • (D) Builder
💬 Discuss
✅ Correct Answer: (B) Singleton

Explanation: It returns the same PDO instance (singleton).