call_cognitive_endpoint {AzureCognitive} | R Documentation |
Call a Cognitive Service REST endpoint
Description
Call a Cognitive Service REST endpoint
Usage
call_cognitive_endpoint(endpoint, ...)
## S3 method for class 'cognitive_endpoint'
call_cognitive_endpoint(endpoint, operation,
options = list(), headers = list(), body = NULL, encode = NULL, ...,
http_verb = c("GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"),
http_status_handler = c("stop", "warn", "message", "pass"))
Arguments
endpoint |
An object of class |
... |
Further arguments passed to lower-level functions. For the default method, these are passed to |
operation |
The operation to perform. |
options |
Any query parameters that the operation takes. |
headers |
Any optional HTTP headers to include in the REST call. Note that |
body |
The body of the HTTP request for the REST call. |
encode |
The encoding (really content-type) for the body. See the |
http_verb |
The HTTP verb for the REST call. |
http_status_handler |
How to handle a failed REST call. |
Details
This function does the low-level work of constructing a HTTP request and then calling the REST endpoint. It is meant to be used by other packages that provide higher-level views of the service functionality.
Value
For a successful REST call, the contents of the response. This will usually be a list, obtained by translating the raw JSON body into R. If the call returns a non-success HTTP status code, based on the http_status_handler
argument.
See Also
cognitive_endpoint, create_cognitive_service, get_cognitive_service
Examples
## Not run:
endp <- cognitive_endpoint("https://myvisionservice.api.cognitive.azure.com",
service_type="Computervision", key="key")
# analyze an online image
img_link <- "https://news.microsoft.com/uploads/2014/09/billg1_print.jpg"
call_cognitive_endpoint(endp,
operation="analyze",
body=list(url=img_link),
options=list(details="celebrities"),
http_verb="POST")
# analyze an image on the local machine
img_raw <- readBin("image.jpg", "raw", file.info("image.jpg")$size)
call_cognitive_endpoint(endp,
operation="analyze",
body=img_raw,
encode="raw",
http_verb="POST")
## End(Not run)