HTTP
Types
EasyCurl.HTTPResponse
— TypeHTTPResponse <: CurlResponse
An HTTP response object returned on a request completion.
Fields
Name | Description | Accessors (get ) |
---|---|---|
status::Int | The HTTP status code of the response. | http_status(x) |
version::Int | The HTTP version received in the response. | http_version(x) |
total_time::Float64 | Total time spent receiving a response in seconds. | http_total_time(x) , curl_total_time(x) |
body::Vector{UInt8} | The response body as a vector of bytes. | http_body(x) , curl_body(x) |
headers::Vector{Pair{String,String}} | Headers received in the HTTP response. | http_headers(x) |
EasyCurl.HTTPOptions
— TypeHTTPOptions <: CurlOptions
Represents options for configuring an HTTP request.
Fields
Name | Description | Default |
---|---|---|
location::Bool | Allow HTTP redirects. | true |
max_redirs::Int | Maximum number of redirects. | 10 |
connect_timeout::Real | Maximum time in seconds that you allow the connection phase to take. | 10 |
read_timeout::Real | Timeout in seconds for reading the response. | 30 |
ssl_verifyhost::Bool | Enables SSL certificate's host verification. | true |
ssl_verifypeer::Bool | Enables the SSL certificate verification. | true |
verbose::Bool | Enables detailed output from Curl (useful for debugging). | false |
username::Union{String,Nothing} | Username for authentication. | nothing |
password::Union{String,Nothing} | Password for authentication. | nothing |
proxy::Union{String,Nothing} | Proxy server URL, or nothing to bypass proxy settings. | nothing |
interface::Union{String,Nothing} | Specifies a particular network interface to use for the request, or nothing to use the default. | nothing |
accept_encoding::Union{String,Nothing} | Specifies the accepted encodings for the response, such as "gzip" . | nothing |
version::Union{UInt,Nothing} | Specifies the CURL version to use, or nothing to use the default version available. | nothing |
Methods
EasyCurl.http_request
— Functionhttp_request(method::String, url::String; kw...) -> HTTPResponse
Send a url
HTTP request using as method
one of "GET"
, "POST"
, etc. and return a HTTPResponse
object.
Keyword arguments
Name | Description | Default |
---|---|---|
query | Request query dictionary or string. | nothing |
body | Request body. | UInt8[] |
headers::Vector{Pair{String,String}} | Request headers. | Pair{String,String}[] |
status_exception::Bool | Whether to throw an exception if the response status code indicates an error. | true |
retry::Int64 | Number of retries. | 0 |
retry_delay::Real | Delay after failed request. | 0.25 |
options... | Another HTTP request options. |
Examples
julia> response = http_request(
"POST",
"http://httpbin.org/post";
headers = Pair{String,String}[
"Content-Type" => "application/json",
"User-Agent" => "EasyCurl.jl",
],
query = "qry=你好嗎",
body = "{"data":"hi"}",
interface = "en0",
read_timeout = 5,
connect_timeout = 10,
retry = 10,
);
julia> http_body(response) |> String |> print
{
"args": {
"qry": "你好嗎"
},
"data": "{"data":"hi"}",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip",
"Content-Length": "13",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "EasyCurl.jl",
"X-Amzn-Trace-Id": "Root=1-66e0d404-7597b1921ad026293b805690"
},
"json": {
"data": "hi"
},
"origin": "100.250.50.140",
"url": "http://httpbin.org/post?qry=你好嗎"
}
EasyCurl.http_get
— Functionhttp_get(url::AbstractString; kw...) -> HTTPResponse
Shortcut for http_request
function, work similar to http_request("GET", url; kw...)
.
Examples
julia> response = http_get(
"http://httpbin.org/get";
headers = Pair{String,String}[
"Content-Type" => "application/json",
"User-Agent" => "EasyCurl.jl",
],
query = Dict("qry" => "你好嗎"),
);
julia> http_body(response) |> String |> print
{
"args": {
"qry": "你好嗎"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "EasyCurl.jl",
"X-Amzn-Trace-Id": "Root=1-66e0e18f-0e26d7757885d0ec1966ef64"
},
"origin": "100.250.50.140",
"url": "http://httpbin.org/get?qry=你好嗎"
}
EasyCurl.http_head
— Functionhttp_head(url::AbstractString; kw...) -> HTTPResponse
Shortcut for http_request
function, work similar to http_request("HEAD", url; kw...)
.
Examples
julia> response = http_head(
"http://httpbin.org/get";
headers = Pair{String,String}[
"Content-Type" => "application/json",
"User-Agent" => "EasyCurl.jl",
],
query = "qry=你好嗎",
interface = "0.0.0.0",
);
julia> http_body(response)
UInt8[]
EasyCurl.http_post
— Functionhttp_post(url::AbstractString; kw...) -> HTTPResponse
Shortcut for http_request
function, work similar to http_request("POST", url; kw...)
.
Examples
julia> response = http_post(
"http://httpbin.org/post";
headers = Pair{String,String}[
"Content-Type" => "application/json",
"User-Agent" => "EasyCurl.jl",
],
query = "qry=你好嗎",
body = "{"data":"hi"}",
);
julia> http_body(response) |> String |> print
{
"args": {
"qry": "你好嗎"
},
"data": "{"data":"hi"}",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip",
"Content-Length": "13",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "EasyCurl.jl",
"X-Amzn-Trace-Id": "Root=1-66e0e208-4850928003a928fd230bfd59"
},
"json": {
"data": "hi"
},
"origin": "100.250.50.140",
"url": "http://httpbin.org/post?qry=你好嗎"
}
EasyCurl.http_put
— Functionhttp_put(url::AbstractString; kw...) -> HTTPResponse
Shortcut for http_request
function, work similar to http_request("PUT", url; kw...)
.
Examples
julia> response = http_put(
"http://httpbin.org/put";
headers = Pair{String,String}[
"Content-Type" => "application/json",
"User-Agent" => "EasyCurl.jl",
],
query = "qry=你好嗎",
body = "{"data":"hi"}",
);
julia> http_body(response) |> String |> print
{
"args": {
"qry": "你好嗎"
},
"data": "{"data":"hi"}",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip",
"Content-Length": "13",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "EasyCurl.jl",
"X-Amzn-Trace-Id": "Root=1-66e0e239-34f8cfdc41164300719ce1f1"
},
"json": {
"data": "hi"
},
"origin": "100.250.50.140",
"url": "http://httpbin.org/put?qry=你好嗎"
}
EasyCurl.http_patch
— Functionhttp_patch(url::AbstractString; kw...) -> HTTPResponse
Shortcut for http_request
function, work similar to http_request("PATCH", url; kw...)
.
Examples
julia> response = http_patch(
"http://httpbin.org/patch";
headers = Pair{String,String}[
"Content-Type" => "application/json",
"User-Agent" => "EasyCurl.jl",
],
query = "qry=你好嗎",
body = "{"data":"hi"}",
);
julia> http_body(response) |> String |> print
{
"args": {
"qry": "你好嗎"
},
"data": "{"data":"hi"}",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip",
"Content-Length": "13",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "EasyCurl.jl",
"X-Amzn-Trace-Id": "Root=1-66e0e266-5bd4762c619fbd642710bf3d"
},
"json": {
"data": "hi"
},
"origin": "100.250.50.140",
"url": "http://httpbin.org/patch?qry=你好嗎"
}
EasyCurl.http_delete
— Functionhttp_delete(url::AbstractString; kw...) -> HTTPResponse
Shortcut for http_request
function, work similar to http_request("DELETE", url; kw...)
.
Examples
julia> response = http_delete(
"http://httpbin.org/delete";
headers = Pair{String,String}[
"Content-Type" => "application/json",
"User-Agent" => "EasyCurl.jl",
],
query = "qry=你好嗎",
body = "{"data":"hi"}",
);
julia> http_body(response) |> String |> print
{
"args": {
"qry": "你好嗎"
},
"data": "{"data":"hi"}",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip",
"Content-Length": "13",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "EasyCurl.jl",
"X-Amzn-Trace-Id": "Root=1-66e0e292-34acbab950035ea1763c3aca"
},
"json": {
"data": "hi"
},
"origin": "100.250.50.140",
"url": "http://httpbin.org/delete?qry=你好嗎"
}
Utilities
EasyCurl.http_iserror
— Functionhttp_iserror(x::HTTPResponse) -> Bool
Determines if the HTTP response indicates an error (status codes 400 and above).
Examples
julia> response = http_request("GET", "http://httpbin.org/get");
julia> http_iserror(response)
false
EasyCurl.http_headers
— Functionhttp_headers(x::HTTPResponse, key::String) -> Vector{String}
Retrieve all values for a specific header field from a HTTPResponse
object. This function is case-insensitive with regard to the header field name.
Examples
julia> response = http_request("GET", "http://httpbin.org/get");
julia> http_headers(response, "Content-Type")
1-element Vector{String}:
"application/json"
julia> http_headers(response, "nonexistent-header")
String[]
EasyCurl.http_header
— Functionhttp_header(x::HTTPResponse, key::String, default = nothing)
Retrieve the first value of a specific header field by key
from a HTTPResponse
object. If the header is not found, the function returns a default
value. This function is case-insensitive with regard to the header field name.
Examples
julia> response = http_request("GET", "http://httpbin.org/get");
julia> http_header(response, "Content-Type")
"application/json"
julia> http_header(response, "nonexistent-header", "default-value")
"default-value"
EasyCurl.HTTP_VERSION_MAP
— ConstantHTTP_VERSION_MAP::Dict{UInt64,String}
Maps CURL numerical constants for HTTP versions to their string representations.
0x00000001
(CURL_HTTP_VERSION_1_0
) -"1.0"
: HTTP 1.00x00000002
(CURL_HTTP_VERSION_1_1
) -"1.1"
: HTTP 1.10x00000003
(CURL_HTTP_VERSION_2_0
) -"2.0"
: HTTP 2.0