Enhance your knowledge of PHP API handling with this set of 30 multiple-choice questions. Dive into key topics such as sending HTTP requests, understanding RESTful APIs, consuming JSON/XML, and handling authentication.
Which HTTP method is used to retrieve data from a server in RESTful APIs? A) GET B) POST C) PUT D) DELETE
Which HTTP method is used to send data to the server in RESTful APIs? A) GET B) POST C) PUT D) DELETE
In which scenario would you use the PUT HTTP method in a RESTful API? A) To retrieve data from a server B) To delete existing data from a server C) To update an existing resource D) To create a new resource
Which HTTP method is typically used for deleting data in RESTful APIs? A) GET B) POST C) PUT D) DELETE
Which of the following is a feature of the HTTP GET request? A) It submits form data B) It retrieves data from the server C) It updates data on the server D) It deletes data from the server
How do you send form data in a POST request in PHP? A) Using the $_GET superglobal B) Using the $_POST superglobal C) Using http_build_query() D) Using file_get_contents()
What is a characteristic of the PUT request in HTTP? A) It can create new resources on the server B) It replaces an existing resource entirely C) It retrieves data from the server D) It deletes resources from the server
Which of the following methods can be used to make a DELETE request in PHP? A) file_get_contents() B) curl_setopt() with CURLOPT_CUSTOMREQUEST C) $_POST D) $_DELETE
How can you pass parameters in a GET request in PHP? A) Using the URL query string B) Using headers C) Using the request body D) Using cookies
Which HTTP method would you use to send JSON data to the server in PHP? A) GET B) POST C) PUT D) DELETE
What does REST stand for in RESTful APIs? A) Representational State Transfer B) Real-time Service Technology C) Reliable Simple Transfer D) Remote Event Service
Which of the following is a key constraint of RESTful APIs? A) Statelessness B) Real-time communication C) Encryption D) Synchronous communication
What is the primary purpose of a RESTful API? A) To transfer files between clients B) To manage stateful sessions C) To provide access to resources over HTTP D) To serve static HTML content
Which data format is commonly used in RESTful APIs? A) XML B) JSON C) CSV D) HTML
What is a resource in the context of a RESTful API? A) A type of HTTP request B) An endpoint to retrieve or manipulate data C) A function to validate data D) A method for handling errors
In REST, what is the purpose of HTTP status codes? A) To indicate the type of resource B) To track the time of the request C) To show the result of an HTTP request D) To encrypt the response
Which of the following HTTP methods is typically used to retrieve a resource in a RESTful API? A) GET B) PUT C) POST D) DELETE
What does the HTTP status code 200 indicate? A) Internal Server Error B) Not Found C) Success D) Unauthorized
Which of the following is an example of a RESTful API request? A) GET /users/123 B) POST /upload C) PUT /update-item D) DELETE /delete-item
How does RESTful API differ from SOAP? A) SOAP uses XML, while REST uses JSON B) REST is more secure than SOAP C) SOAP is faster than REST D) SOAP is simpler to implement than REST
Topic 3: Consuming JSON and XML Data (5 Questions)
Which PHP function is used to decode JSON data into a PHP variable? A) json_decode() B) json_encode() C) xml_decode() D) json_parse()
How do you convert a PHP array into a JSON string in PHP? A) json_encode() B) json_decode() C) serialize() D) xml_encode()
Which PHP function is used to parse XML data? A) xml_parse() B) json_decode() C) simplexml_load_string() D) xml_decode()
What does the json_decode() function return in PHP? A) A JSON object B) A PHP object or array C) An array of XML data D) A string containing JSON
How do you retrieve XML data from a file using PHP? A) file_get_contents() B) simplexml_load_file() C) xml_parser() D) xml_decode()
Topic 4: PHP cURL Functions (5 Questions)
Which PHP function is used to initialize a cURL session? A) curl_init() B) curl_start() C) curl_set() D) curl_execute()
What does the curl_setopt() function do in PHP? A) Initializes a cURL session B) Sets options for the cURL session C) Executes the cURL session D) Closes the cURL session
Which function is used to execute a cURL session in PHP? A) curl_execute() B) curl_exec() C) curl_do() D) curl_run()
How do you retrieve the response from a cURL session in PHP? A) curl_response() B) curl_get_response() C) curl_exec() D) curl_output()
Which cURL option is used to set the URL for a cURL session in PHP? A) CURLOPT_URL B) CURLOPT_METHOD C) CURLOPT_COOKIE D) CURLOPT_HEADER