EasyCurl.HTTP_STATUS_CODESConstant
HTTP_STATUS_CODES

A dictionary that maps HTTP status codes to their corresponding messages:

  • 100 - CONTINUE
  • 101 - SWITCHING_PROTOCOLS
  • 102 - PROCESSING
  • 103 - EARLY_HINTS
  • 200 - OK
  • 201 - CREATED
  • 202 - ACCEPTED
  • 203 - NON_AUTHORITATIVE_INFORMATION
  • 204 - NO_CONTENT
  • 205 - RESET_CONTENT
  • 206 - PARTIAL_CONTENT
  • 207 - MULTI_STATUS
  • 208 - ALREADY_REPORTED
  • 226 - IM_USED
  • 300 - MULTIPLE_CHOICES
  • 301 - MOVED_PERMANENTLY
  • 302 - FOUND
  • 303 - SEE_OTHER
  • 304 - NOT_MODIFIED
  • 307 - TEMPORARY_REDIRECT
  • 308 - PERMANENT_REDIRECT
  • 400 - BAD_REQUEST
  • 401 - UNAUTHORIZED
  • 402 - PAYMENT_REQUIRED
  • 403 - FORBIDDEN
  • 404 - NOT_FOUND
  • 405 - METHOD_NOT_ALLOWED
  • 406 - NOT_ACCEPTABLE
  • 407 - PROXY_AUTHENTICATION_REQUIRED
  • 408 - REQUEST_TIMEOUT
  • 409 - CONFLICT
  • 410 - GONE
  • 411 - LENGTH_REQUIRED
  • 412 - PRECONDITION_FAILED
  • 413 - PAYLOAD_TOO_LARGE
  • 414 - URI_TOO_LONG
  • 415 - UNSUPPORTED_MEDIA_TYPE
  • 416 - RANGE_NOT_SATISFIABLE
  • 417 - EXPECTATION_FAILED
  • 418 - IM_A_TEAPOT
  • 421 - MISDIRECTED_REQUEST
  • 422 - UNPROCESSABLE_ENTITY
  • 423 - LOCKED
  • 424 - FAILED_DEPENDENCY
  • 425 - TOO_EARLY
  • 426 - UPGRADE_REQUIRED
  • 428 - PRECONDITION_REQUIRED
  • 429 - TOO_MANY_REQUESTS
  • 431 - REQUEST_HEADER_FIELDS_TOO_LARGE
  • 451 - UNAVAILABLE_FOR_LEGAL_REASONS
  • 500 - INTERNAL_SERVER_ERROR
  • 501 - NOT_IMPLEMENTED
  • 502 - BAD_GATEWAY
  • 503 - SERVICE_UNAVAILABLE
  • 504 - GATEWAY_TIMEOUT
  • 505 - HTTP_VERSION_NOT_SUPPORTED
  • 506 - VARIANT_ALSO_NEGOTIATES
  • 507 - INSUFFICIENT_STORAGE
  • 508 - LOOP_DETECTED
  • 510 - NOT_EXTENDED
  • 511 - NETWORK_AUTHENTICATION_REQUIRED
EasyCurl.EasyCurlErrorType
EasyCurlError{code} <: Exception

Type that is returned if curl_request fails on the libcurl side.

Fields

Examples

julia> curl_request("GET", "http://httpbin.org/status/400", interface = "9.9.9.9")
ERROR: EasyCurlError{45}(Failed binding local connection end)
[...]

julia> curl_request("GET", "http://httpbin.org/status/400", interface = "")
ERROR: EasyCurlError{7}(Couldn't connect to server)
[...]
EasyCurl.EasyCurlStatusErrorType
EasyCurlStatusError{code} <: Exception

Type that is returned if curl_request fails on the HTTP side.

Fields

  • code::Int64: The HTTP error code (see HTTP_STATUS_CODES).
  • message::String: The error message.
  • response::Response: The HTTP response object.

Examples

julia> curl_request("GET", "http://httpbin.org/status/400", interface = "0.0.0.0")
ERROR: EasyCurlStatusError{400}(BAD_REQUEST)
[...]

julia> curl_request("GET", "http://httpbin.org/status/404", interface = "0.0.0.0")
ERROR: EasyCurlStatusError{404}(NOT_FOUND)
[...]
EasyCurl.RequestType
Request

Represents an HTTP request object.

Fields

  • method::String: The HTTP request method (e.g. "GET", "POST", etc.).
  • url::String: The URL to which the request is sent.
  • headers::Vector{Pair{String, String}}: Headers for the HTTP request.
  • body::Vector{UInt8}: The request body as a vector of bytes.
  • connect_timeout::Real: The connection timeout for the request in seconds.
  • read_timeout::Real: The read timeout for the response in seconds.
  • interface::Union{String, Nothing}: The network interface to use (or nothing for the default).
  • proxy::Union{String, Nothing}: The proxy server to use (or nothing for no proxy).
  • accept_encoding::String: The accepted encoding for the response (e.g., "gzip").
  • ssl_verifypeer::Bool: Whether to verify SSL certificates.
  • verbose::Bool: Enables verbose output from EasyCurl for debugging.
  • rq_curl::Ptr{CURL}: A pointer to a EasyCurl handle for the request.
  • rq_multi::Ptr{CURL}: A pointer to a EasyCurl multi handle for the request.
  • response::CurlResponse: The HTTP response associated with this request.
EasyCurl.ResponseType
EasyCurl.Response(x::CurlResponse)

Represents an HTTP response object that can be received from a CurlResponse.

Fields

  • status::Int64: The HTTP status code of the response.
  • request_time::Float64: The time taken for the HTTP request in seconds.
  • headers::Vector{Pair{String,String}}: Headers received in the HTTP response.
  • body::Vector{UInt8}: The response body as a vector of bytes.

See also: curl_status, curl_request_time, curl_headers, curl_body, curl_iserror

EasyCurl.curl_deleteMethod
curl_delete(url::AbstractString; kw...) -> EasyCurl.Response

Shortcut for curl_request function, work similar to curl_request("DELETE", url; kw...).

Examples

julia> headers = Pair{String,String}[
    "User-Agent" => "EasyCurl.jl",
    "Content-Type" => "application/json"
]

julia> response = curl_delete("http://httpbin.org/delete", headers = headers,
    query = "qry=你好嗎", body = "{\"data\":\"hi\"}")

julia> curl_status(response)
200

julia> curl_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-6589e5f7-1c1ff2407f567ff17786576d"
  },
  "json": {
    "data": "hi"
  },
  "origin": "100.250.50.140",
  "url": "http://httpbin.org/delete?qry=你好嗎"
}
EasyCurl.curl_getMethod
curl_get(url::AbstractString; kw...) -> EasyCurl.Response

Shortcut for curl_request function, work similar to curl_request("GET", url; kw...).

Examples

julia> headers = Pair{String,String}[
    "User-Agent" => "EasyCurl.jl",
    "Content-Type" => "application/json"
]

julia> response = curl_get("http://httpbin.org/get", headers = headers,
    query = Dict{String,String}("qry" => "你好嗎"))

julia> curl_status(response)
200

julia> curl_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-6589e259-24815d6d62da962a06fc7edf"
  },
  "origin": "100.250.50.140",
  "url": "http://httpbin.org/get?qry=你好嗎"
}
EasyCurl.curl_headMethod
curl_head(url::AbstractString; kw...) -> EasyCurl.Response

Shortcut for curl_request function, work similar to curl_request("HEAD", url; kw...).

Examples

julia> headers = Pair{String,String}[
    "User-Agent" => "EasyCurl.jl",
    "Content-Type" => "application/json"
]

julia> response = curl_head("http://httpbin.org/get", headers = headers,
    query = "qry=你好嗎", interface = "0.0.0.0")

julia> curl_status(response)
200

julia> curl_body(response)
UInt8[]
EasyCurl.curl_patchMethod
curl_patch(url::AbstractString; kw...) -> EasyCurl.Response

Shortcut for curl_request function, work similar to curl_request("PATCH", url; kw...).

Examples

julia> headers = Pair{String,String}[
    "User-Agent" => "EasyCurl.jl",
    "Content-Type" => "application/json"
]

julia> response = curl_patch("http://httpbin.org/patch", headers = headers,
    query = "qry=你好嗎", body = "{\"data\":\"hi\"}")

julia> curl_status(response)
200

julia> curl_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-6589e410-33f8cb5a31db9fba6c0a746f"
  },
  "json": {
    "data": "hi"
  },
  "origin": "100.250.50.140",
  "url": "http://httpbin.org/patch?qry=你好嗎"
}
EasyCurl.curl_postMethod
curl_post(url::AbstractString; kw...) -> EasyCurl.Response

Shortcut for curl_request function, work similar to curl_request("POST", url; kw...).

Examples

julia> headers = Pair{String,String}[
    "User-Agent" => "EasyCurl.jl",
    "Content-Type" => "application/json"
]

julia> response = curl_post("http://httpbin.org/post", headers = headers,
    query = "qry=你好嗎", body = "{\"data\":\"hi\"}")

julia> curl_status(response)
200

julia> curl_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-6589e32c-7f09b85d56e11aea59cde1d6"
  },
  "json": {
    "data": "hi"
  },
  "origin": "100.250.50.140",
  "url": "http://httpbin.org/post?qry=你好嗎"
}
EasyCurl.curl_putMethod
curl_put(url::AbstractString; kw...) -> EasyCurl.Response

Shortcut for curl_request function, work similar to curl_request("PUT", url; kw...).

Examples

julia> headers = Pair{String,String}[
    "User-Agent" => "EasyCurl.jl",
    "Content-Type" => "application/json"
]

julia> response = curl_put("http://httpbin.org/put", headers = headers,
    query = "qry=你好嗎", body = "{\"data\":\"hi\"}")

julia> curl_status(response)
200

julia> curl_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-6589e3b0-58cdde84399ad8be30eb4e46"
  },
  "json": {
    "data": "hi"
  },
  "origin": "100.250.50.140",
  "url": "http://httpbin.org/put?qry=你好嗎"
}
EasyCurl.curl_requestMethod
curl_request(method::AbstractString, url::AbstractString; kw...) -> EasyCurl.Response

Send a url HTTP Request using as method one of "GET", "POST", etc. and return a EasyCurl.Response object.

Keyword arguments

  • headers = Pair{String,String}[]: The headers for the request.
  • body = nothing: The body for the request.
  • query = nothing: The query string for the request.
  • interface = nothing: The interface for the request.
  • status_exception = true: Whether to throw an exception if the response status code indicates an error.
  • connect_timeout = 60: The connect timeout for the request in seconds.
  • read_timeout = 300: The read timeout for the request in seconds.
  • retries = 1: The number of times to retry the request if an error occurs.
  • proxy = nothing: Which proxy to use for the request.
  • accept_encoding = "gzip": Encoding to accept.
  • verbose::Bool = false: Enables verbose output from EasyCurl for debugging.
  • ssl_verifypeer = true: Whether peer need to be verified.

Examples

julia> headers = Pair{String,String}[
    "User-Agent" => "EasyCurl.jl",
    "Content-Type" => "application/json"
]

julia> response = curl_request("POST", "http://httpbin.org/post", headers = headers, query = "qry=你好嗎",
    body = "{\"data\":\"hi\"}", interface = "en0", read_timeout = 5, connect_timeout = 10, retries = 10)

julia> curl_status(response)
200

julia> curl_body(response) |> String |> print
{
  "headers": {
    "X-Amzn-Trace-Id": "Root=1-6588a009-19f3dc0321bee38106226bb3",
    "Content-Length": "13",
    "Host": "httpbin.org",
    "Accept": "*/*",
    "Content-Type": "application/json",
    "Accept-Encoding": "gzip",
    "User-Agent": "EasyCurl.jl"
  },
  "json": {
    "data": "hi"
  },
  "files": {},
  "args": {
    "qry": "你好嗎"
  },
  "data": "{\"data\":\"hi\"}",
  "url": "http://httpbin.org/post?qry=你好嗎",
  "form": {},
  "origin": "100.250.50.140"
}
EasyCurl.joinurlMethod
EasyCurl.joinurl(basepart::AbstractString, parts::AbstractString...)::String

Construct a URL by concatenating a base part with one or more path segments. This function ensures that each segment is separated by a single forward slash (/), regardless of whether the basepart or parts already contain slashes at their boundaries.

Examples

julia> EasyCurl.joinurl("http://example.com", "path")
"http://example.com/path"

julia> EasyCurl.joinurl("http://example.com/", "/path/to/resource")
"http://example.com/path/to/resource"
EasyCurl.urldecodeMethod
EasyCurl.urldecode(s::AbstractString)

Decode an encoded URI string s back to normal string.

Examples

julia> EasyCurl.urldecode("%5Bcurl%5D")
"[curl]"
EasyCurl.urlencodeMethod
EasyCurl.urlencode(s::AbstractString)

Encode a string s into URI using only the US-ASCII characters legal within a URI.

Examples

julia> EasyCurl.urlencode("[curl]")
"%5Bcurl%5D"