Programming MCQs Feed

📊 Trishul API
Q. How do you access a specific HTTP header?
Code:
$auth = $request->header()->get('Authorization');
  • (A) header()
  • (B) get_header()
  • (C) headers()
  • (D) fetch_header()
💬 Discuss
✅ Correct Answer: (A) header()

Explanation: header() returns the Header object used to access headers.

📊 Trishul API
Q. Which method returns the request body?
  • (A) get_body()
  • (B) body()
  • (C) request_body()
  • (D) payload()
💬 Discuss
✅ Correct Answer: (B) body()

Explanation: body() returns the RequestBody object.

📊 Trishul API
Q. Which method is used to retrieve session data?
Code:
$userId = $request->____()->get('user_id');
  • (A) cookie
  • (B) header
  • (C) session
  • (D) path
💬 Discuss
✅ Correct Answer: (C) session

Explanation: session() returns the Session object to manage session data.

📊 Trishul API
Q. Which method is used to get cookies?
Code:
$token = $request->____()->get('session_token');
  • (A) cookie
  • (B) session
  • (C) header
  • (D) body
💬 Discuss
✅ Correct Answer: (A) cookie

Explanation: cookie() returns the Cookie object for accessing cookies.

📊 Trishul API
Q. How do you get path variables from the request?
Code:
$id = $request->____()->get('id');
  • (A) query_params
  • (B) path
  • (C) body
  • (D) header
💬 Discuss
✅ Correct Answer: (B) path

Explanation: path() returns the PathVariable object.

📊 Trishul API
Q. Which method returns the request URL?
Code:
$url = $request->____();
  • (A) url
  • (B) getUrl
  • (C) get_url
  • (D) fetch_url
💬 Discuss
✅ Correct Answer: (C) get_url

Explanation: get_url() returns the current request URL.

📊 Trishul API
Q. Which method returns the client's IP address?
Code:
$ip = $request->____();
  • (A) client_ip
  • (B) get_ip
  • (C) ip
  • (D) remote_ip
💬 Discuss
✅ Correct Answer: (B) get_ip

Explanation: get_ip() returns the client's IP.

📊 Trishul API
Q. What does the update() method do?
  • (A) Deletes request data
  • (B) Updates current request with another request
  • (C) Creates a new request
  • (D) Resets request data
💬 Discuss
✅ Correct Answer: (B) Updates current request with another request

Explanation: update() merges data from another Request object.

📊 Trishul API
Q. Which method sets the request body?
  • (A) set_body
  • (B) body_set
  • (C) update_body
  • (D) assign_body
💬 Discuss
✅ Correct Answer: (A) set_body

Explanation: set_body() assigns a RequestBody object.

📊 Trishul API
Q. What happens if set_body() is called with null body?
  • (A) Returns false
  • (B) Throws NullPointerException
  • (C) Ignores the call
  • (D) Creates empty body
💬 Discuss
✅ Correct Answer: (B) Throws NullPointerException

Explanation: It throws NullPointerException if the body is null.