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 cognitive_endpoint.

...

Further arguments passed to lower-level functions. For the default method, these are passed to httr::content; in particular, you can convert a structured JSON response into a data frame by specifying simplifyDataFrame=TRUE.

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 call_cognitive_endpoint will handle authentication details automatically, so don't include them here.

body

The body of the HTTP request for the REST call.

encode

The encoding (really content-type) for the body. See the encode argument for httr::POST. The default value of NULL will use raw encoding if the body is a raw vector, and json encoding for anything else.

http_verb

The HTTP verb for the REST call.

http_status_handler

How to handle a failed REST call. stop, warn and message will call the corresponding ⁠*_for_status⁠ handler in the httr package; pass will return the raw response object unchanged. The last one is mostly intended for debugging purposes.

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)

[Package AzureCognitive version 1.0.1 Index]