Debian Codegraph @

man/ncurl.Rd

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