View source: R/send_api_request.R
send_api_request | R Documentation |
This function sends an HTTP request (GET or POST) to the specified URL. It supports optional request bodies for POST requests, customizable encoding, and content type for API interactions. The function is designed to be a general-purpose API handler for use in querying external APIs.
send_api_request(
url,
method = "GET",
body = NULL,
encode = "json",
content_type = "application/json",
verbosity = TRUE
)
url |
A string representing the target URL for the API request. |
method |
A string specifying the HTTP method to use. The default is "GET", but "POST" can also be used. |
body |
Optional: The body of the request, typically required for POST requests. Default is |
encode |
A string representing the encoding type of the body for POST requests. Default is |
content_type |
A string specifying the content type for POST requests. Default is |
verbosity |
Logical flag indicating whether to print status messages during the function execution. Default is |
The send_api_request
function is a flexible tool for handling API interactions. It supports both GET and POST methods and provides optional parameters for encoding and content type, making it suitable for a wide range of API requests.
If a network error occurs during the request, the function will throw an error with a detailed message about the failure.
A response object from the httr
package representing the server's response to the API request.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.