| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/ncurl.R |
| 3 |
\name{ncurl_session} |
| 4 |
\alias{ncurl_session} |
| 5 |
\alias{transact} |
| 6 |
\title{ncurl Session} |
| 7 |
\usage{ |
| 8 |
ncurl_session( |
| 9 |
url, |
| 10 |
convert = TRUE, |
| 11 |
method = NULL, |
| 12 |
headers = NULL, |
| 13 |
data = NULL, |
| 14 |
response = NULL, |
| 15 |
timeout = NULL, |
| 16 |
tls = NULL |
| 17 |
) |
| 18 |
|
| 19 |
transact(session) |
| 20 |
} |
| 21 |
\arguments{ |
| 22 |
\item{url}{the URL address.} |
| 23 |
|
| 24 |
\item{convert}{[default TRUE] logical value whether to attempt conversion |
| 25 |
of the received raw bytes to a character vector. Set to \code{FALSE} if |
| 26 |
downloading non-text data.} |
| 27 |
|
| 28 |
\item{method}{(optional) the HTTP method as a character string. Defaults to |
| 29 |
'GET' if not specified, and could also be 'POST', 'PUT' etc.} |
| 30 |
|
| 31 |
\item{headers}{(optional) a named character vector specifying the HTTP |
| 32 |
request headers, for example: \cr |
| 33 |
\code{c(Authorization = "Bearer APIKEY", "Content-Type" = "text/plain")} \cr |
| 34 |
A non-character or non-named vector will be ignored.} |
| 35 |
|
| 36 |
\item{data}{(optional) request data to be submitted. Must be a character |
| 37 |
string or raw vector, and other objects are ignored. If a character vector, |
| 38 |
only the first element is taken. When supplying binary data, the |
| 39 |
appropriate 'Content-Type' header should be set to specify the binary |
| 40 |
format.} |
| 41 |
|
| 42 |
\item{response}{(optional) a character vector specifying the response headers |
| 43 |
to return e.g. \code{c("date", "server")}. These are case-insensitive and |
| 44 |
will return NULL if not present. Specify \code{TRUE} to return all response |
| 45 |
headers. A non-character vector will be ignored (other than \code{TRUE}).} |
| 46 |
|
| 47 |
\item{timeout}{(optional) integer value in milliseconds after which the |
| 48 |
connection and subsequent transact attempts time out.} |
| 49 |
|
| 50 |
\item{tls}{(optional) applicable to secure HTTPS sites only, a client TLS |
| 51 |
Configuration object created by \code{\link[=tls_config]{tls_config()}}. If missing or NULL, |
| 52 |
certificates are not validated.} |
| 53 |
|
| 54 |
\item{session}{an 'ncurlSession' object.} |
| 55 |
} |
| 56 |
\value{ |
| 57 |
For \code{ncurl_session}: an 'ncurlSession' object if successful, or else |
| 58 |
an 'errorValue'. |
| 59 |
|
| 60 |
For \code{transact}: a named list of 3 elements: |
| 61 |
\itemize{ |
| 62 |
\item \verb{$status} - integer HTTP repsonse status code (200 - OK). Use |
| 63 |
\code{\link[=status_code]{status_code()}} for a translation of the meaning. |
| 64 |
\item \verb{$headers} - named list of response headers (all headers if |
| 65 |
\code{response = TRUE} was specified for the session, those specified in |
| 66 |
\code{response}, or NULL otherwise). |
| 67 |
\item \verb{$data} - the response body as a character string (if \code{convert = TRUE} was |
| 68 |
specified for the session), which may be further parsed as html, json, xml |
| 69 |
etc. as required, or else a raw byte vector, which may be saved as a file |
| 70 |
using \code{\link[=writeBin]{writeBin()}}. |
| 71 |
} |
| 72 |
} |
| 73 |
\description{ |
| 74 |
nano cURL - a minimalist http(s) client. A session encapsulates a connection, |
| 75 |
along with all related parameters, and may be used to return data multiple |
| 76 |
times by repeatedly calling \code{transact()}, which transacts once over the |
| 77 |
connection. |
| 78 |
} |
| 79 |
\section{Public Internet HTTPS}{ |
| 80 |
|
| 81 |
|
| 82 |
When making HTTPS requests over the public internet, you should supply a TLS |
| 83 |
configuration to validate server certificates. See \code{\link[=tls_config]{tls_config()}} for |
| 84 |
details. |
| 85 |
} |
| 86 |
|
| 87 |
\examples{ |
| 88 |
s <- ncurl_session( |
| 89 |
"https://postman-echo.com/get", |
| 90 |
response = "date", |
| 91 |
timeout = 2000L |
| 92 |
) |
| 93 |
s |
| 94 |
if (is_ncurl_session(s)) transact(s) |
| 95 |
if (is_ncurl_session(s)) close(s) |
| 96 |
|
| 97 |
} |
| 98 |
\seealso{ |
| 99 |
\code{\link[=ncurl]{ncurl()}} for synchronous http requests; \code{\link[=ncurl_aio]{ncurl_aio()}} for |
| 100 |
asynchronous http requests. |
| 101 |
} |