std::curl
A library for making HTTP requests using the system's curl binary.
You can find a set of examples here.
Functions
-
DELETE(url: str, body: str|buf = "") -> Response|err -
Convenience function for making a simple
DELETErequest. -
GET(url: str) -> Response|err -
Convenience function for making a simple
GETrequest. -
HEAD(url: str) -> Response|err -
Convenience function for making a simple
HEADrequest. -
OPTIONS(url: str) -> Response|err -
Convenience function for making a simple
OPTIONSrequest. -
PATCH(url: str, body: str|buf) -> Response|err -
Convenience function for making a simple
PATCHrequest. -
POST(url: str, body: str|buf) -> Response|err -
Convenience function for making a simple
POSTrequest. -
PUT(url: str, body: str|buf) -> Response|err -
Convenience function for making a simple
PUTrequest.
Requests
-
Request() -> Request -
Creates a new
Requestobject.
Request objects have the following public methods:
-
:append_args(*args: str) -> Request -
Appends custom arguments for the
curlbinary.Returns the request object to enable chaining.
-
:body(value: str|buf) -> Request -
Sets the request's body to
value.Returns the request object to enable chaining.
-
:debug() -> Request -
Turns on debug mode. Debug output is printed to the standard error stream.
Returns the request object to enable chaining.
-
:header(value: str) -> Request -
Adds a header to the request.
Returns the request object to enable chaining.
-
:http_auth(username: str, password: str) -> Request -
Adds authentication credentials in Basic HTTP Authentication format.
Returns the request object to enable chaining.
-
:url(value: str) -> Request -
Sets the request's URL.
Returns the request object to enable chaining.
-
:param(key: any, value: any) -> Request -
Adds a key/value parameter pair to the request —
keyandvaluewill be automatically stringified if they are not already strings.If the request is one of (
GET,HEAD,OPTIONS), the parameter pair will be URL-encoded and appended to the URL's query string.If the request is one of (
POST,PUT,PATCH,DELETE), the parameter pair will be URL-encoded and appended to the request's body inapplication/x-www-form-urlencodedformat. The appropriateContent-Typeheader will be automatically added to the request.Returns the request object to enable chaining.
-
:timeout(seconds: f64) -> Request -
Sets a timeout for the request, measured in (fractional) seconds. If the request hangs for longer than the specified timeout, it will return an
err.Returns the request object to enable chaining.
-
:DELETE() -> Response|err -
Sends a
DELETErequest. -
:GET() -> Response|err -
Sends a
GETrequest. -
:HEAD() -> Response|err -
Sends a
HEADrequest. -
:OPTIONS() -> Response|err -
Sends an
OPTIONSrequest. -
:PATCH() -> Response|err -
Sends a
PATCHrequest. -
:POST() -> Response|err -
Sends a
POSTrequest. -
:PUT() -> Response|err -
Sends a
PUTrequest.
Responses
Response objects have the following public fields:
class Response { # The response's HTTP status code. pub var code: i64; # The response's body. pub var body: buf; # The response's headers, including the status line. pub var raw_headers: str; # The response's headers as a map of key/value pairs. # Keys are converted to lower-case ASCII. pub var headers: map[str, str]; }
Response objects have the following public methods:
-
:from_json() -> map|vec|str|i64|f64|bool|null|err -
Attempts to parse the response body as JSON. Returns the resulting value.
Returns an
errif the response body is not valid JSON. -
:has_header(key: str) -> bool -
Returns
trueif the response has a header namedkey, wherekeyis a case-insensitive string. -
:header(key: str) -> str|err -
Returns the value of the header
key, wherekeyis a case-insensitive string.Returns an
errif the header does not exist.