Debian Codegraph @

man/ncurl_aio.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/ncurl.R
3 \name{ncurl_aio}
4 \alias{ncurl_aio}
5 \title{ncurl Async}
6 \usage{
7 ncurl_aio(
8 url,
9 convert = TRUE,
10 method = NULL,
11 headers = NULL,
12 data = NULL,
13 response = NULL,
14 timeout = NULL,
15 tls = NULL
16 )
17 }
18 \arguments{
19 \item{url}{the URL address.}
20
21 \item{convert}{[default TRUE] logical value whether to attempt conversion
22 of the received raw bytes to a character vector. Set to \code{FALSE} if
23 downloading non-text data.}
24
25 \item{method}{(optional) the HTTP method as a character string. Defaults to
26 'GET' if not specified, and could also be 'POST', 'PUT' etc.}
27
28 \item{headers}{(optional) a named character vector specifying the HTTP
29 request headers, for example: \cr
30 \code{c(Authorization = "Bearer APIKEY", "Content-Type" = "text/plain")} \cr
31 A non-character or non-named vector will be ignored.}
32
33 \item{data}{(optional) request data to be submitted. Must be a character
34 string or raw vector, and other objects are ignored. If a character vector,
35 only the first element is taken. When supplying binary data, the
36 appropriate 'Content-Type' header should be set to specify the binary
37 format.}
38
39 \item{response}{(optional) a character vector specifying the response headers
40 to return e.g. \code{c("date", "server")}. These are case-insensitive and
41 will return NULL if not present. Specify \code{TRUE} to return all response
42 headers. A non-character vector will be ignored (other than \code{TRUE}).}
43
44 \item{timeout}{(optional) integer value in milliseconds after which the
45 transaction times out if not yet complete.}
46
47 \item{tls}{(optional) applicable to secure HTTPS sites only, a client TLS
48 Configuration object created by \code{\link[=tls_config]{tls_config()}}. If missing or NULL,
49 certificates are not validated.}
50 }
51 \value{
52 An 'ncurlAio' (object of class 'ncurlAio' and 'recvAio') (invisibly).
53 The following elements may be accessed:
54 \itemize{
55 \item \verb{$status} - integer HTTP repsonse status code (200 - OK). Use
56 \code{\link[=status_code]{status_code()}} for a translation of the meaning.
57 \item \verb{$headers} - named list of response headers (all headers if
58 \code{response = TRUE}, or those specified in \code{response}, or NULL otherwise).
59 If the status code is within the 300 range, i.e. a redirect, the response
60 header 'Location' is automatically appended to return the redirect address.
61 \item \verb{$data} - the response body, as a character string if \code{convert = TRUE} (may
62 be further parsed as html, json, xml etc. as required), or a raw byte
63 vector if FALSE (use \code{\link[=writeBin]{writeBin()}} to save as a file).
64 }
65 }
66 \description{
67 nano cURL - a minimalist http(s) client - async edition.
68 }
69 \section{Promises}{
70
71
72 'ncurlAio' may be used anywhere that accepts a 'promise' from the
73 \CRANpkg{promises} package through the included \code{as.promise} method.
74
75 The promises created are completely event-driven and non-polling.
76
77 If a status code of 200 (OK) is returned then the promise is resolved with
78 the reponse body, otherwise it is rejected with a translation of the status
79 code or 'errorValue' as the case may be.
80 }
81
82 \section{Public Internet HTTPS}{
83
84
85 When making HTTPS requests over the public internet, you should supply a TLS
86 configuration to validate server certificates. See \code{\link[=tls_config]{tls_config()}} for
87 details.
88 }
89
90 \examples{
91 nc <- ncurl_aio(
92 "https://postman-echo.com/get",
93 response = c("date", "server"),
94 timeout = 2000L
95 )
96 call_aio(nc)
97 nc$status
98 nc$headers
99 nc$data
100
101 \dontshow{if (interactive() && requireNamespace("promises", quietly = TRUE)) withAutoprint(\{ # examplesIf}
102 library(promises)
103 p <- as.promise(nc)
104 print(p)
105
106 p2 <- ncurl_aio("https://postman-echo.com/get") \%>\%
107 then(function(x) cat(x$data))
108 is.promise(p2)
109 \dontshow{\}) # examplesIf}
110 }
111 \seealso{
112 \code{\link[=ncurl]{ncurl()}} for synchronous http requests; \code{\link[=ncurl_session]{ncurl_session()}} for
113 persistent connections.
114 }