curl

libcurl bindings for Kit - HTTP client for GET, POST, PUT, DELETE requests

Files

FileDescription
kit.tomlPackage manifest with metadata and dependencies
src/main.kitHTTP client with GET/POST/PUT/DELETE and URL encoding
tests/curl.test.kitTests for error types, constants, and HTTP auth
examples/basic.kitDemo of HTTP requests and URL reachability checks
LICENSEMIT license file

Dependencies

  • csources

Installation

kit add gitlab.com/kit-lang/packages/kit-curl.git

Usage

import Kit.Curl

License

MIT License - see LICENSE for details.

Exported Functions & Types

CurlError

Curl error type for typed error handling. Variants distinguish between different failure modes.

Variants

CurlInitError {message}
CurlConnectionError {message}
CurlTimeoutError {message}
CurlProtocolError {message}
CurlSslError {message}

curle-ok

Success return code (no error).

curle-unsupported-protocol

Unsupported protocol error code.

curle-failed-init

Failed initialization error code.

curle-url-malformat

Malformed URL error code.

curle-couldnt-resolve-host

Could not resolve host error code.

curle-couldnt-connect

Could not connect error code.

curle-operation-timedout

Operation timed out error code.

curle-ssl-connect-error

SSL connection error code.

curlopt-verbose

Enable verbose output option.

curlopt-header

Include header in output option.

curlopt-noprogress

Disable progress meter option.

curlopt-nobody

Do not include body in output option.

curlopt-url

URL to work with option.

curlopt-port

Port number to connect to option.

curlopt-timeout

Maximum time allowed for operation in seconds option.

curlopt-timeout-ms

Maximum time allowed for operation in milliseconds option.

curlopt-connecttimeout

Connection timeout in seconds option.

curlopt-connecttimeout-ms

Connection timeout in milliseconds option.

curlopt-httpget

Force HTTP GET request option.

curlopt-post

Make HTTP POST request option.

curlopt-postfields

POST data to send option.

curlopt-postfieldsize

Size of POST data option.

curlopt-httpheader

Custom HTTP headers option.

curlopt-useragent

User agent string option.

curlopt-referer

Referer header option.

curlopt-followlocation

Follow HTTP redirects option.

curlopt-maxredirs

Maximum number of redirects to follow option.

curlopt-customrequest

Custom HTTP method option.

curlopt-ssl-verifypeer

Verify SSL peer certificate option.

curlopt-ssl-verifyhost

Verify SSL host certificate option.

curlopt-cainfo

CA certificate bundle file path option.

curlopt-capath

CA certificate directory path option.

curlopt-httpauth

HTTP authentication methods option.

curlopt-username

Username for authentication option.

curlopt-password

Password for authentication option.

curlopt-userpwd

Username and password for authentication option.

curlopt-writefunction

Callback for writing received data option.

curlopt-writedata

User data for write callback option.

curlopt-readfunction

Callback for reading data to send option.

curlopt-readdata

User data for read callback option.

curlopt-headerfunction

Callback for processing headers option.

curlopt-headerdata

User data for header callback option.

curlinfo-response-code

HTTP response code info constant.

curlinfo-total-time

Total time for transfer info constant.

curlinfo-namelookup-time

Name lookup time info constant.

curlinfo-connect-time

Connection time info constant.

curlinfo-content-type

Content type info constant.

curlinfo-content-length-download

Content length download info constant.

curlinfo-redirect-count

Redirect count info constant.

curl-global-default

Default global initialization flag.

curl-global-ssl

SSL global initialization flag.

curl-global-win32

Win32 global initialization flag.

curl-global-all

All global initialization flags.

curl-global-nothing

No global initialization flag.

curlauth-basic

Basic HTTP authentication constant.

curlauth-digest

Digest HTTP authentication constant.

curlauth-bearer

Bearer HTTP authentication constant.

get

Note: This module uses Kit's standard Result type (Ok a | Err String).

Performs a simple HTTP GET request.

Sends an HTTP GET request to the specified URL with default settings (30 second timeout, follows redirects automatically).

Parameters:

Returns:

String -> Result String String

result = Curl.get "https://api.github.com/users/octocat"
match result
| Success _ -> print "Data retrieved successfully"
| Error msg -> print "Failed: ${msg}"

post

Performs a simple HTTP POST request with data.

Sends an HTTP POST request to the specified URL with the provided data (30 second timeout, follows redirects automatically).

Parameters:

Returns:

String -> String -> Result String String

payload = "name=John&email=john@example.com"
result = Curl.post "https://api.example.com/users" payload
match result
| Success _ -> print "User created successfully"
| Error msg -> print "Failed: ${msg}"

put

Performs an HTTP PUT request with data.

Sends an HTTP PUT request to the specified URL with the provided data (30 second timeout, follows redirects automatically).

Parameters:

Returns:

String -> String -> Result String String

payload = "{\"name\":\"John Doe\",\"email\":\"john@example.com\"}"
result = Curl.put "https://api.example.com/users/123" payload
match result
| Success _ -> print "User updated successfully"
| Error msg -> print "Failed: ${msg}"

delete

Performs an HTTP DELETE request.

Sends an HTTP DELETE request to the specified URL (30 second timeout, follows redirects automatically).

Parameters:

Returns:

String -> Result String String

result = Curl.delete "https://api.example.com/users/123"
match result
| Success _ -> print "User deleted successfully"
| Error msg -> print "Failed: ${msg}"

head-request

Performs an HTTP HEAD request (headers only).

Sends an HTTP HEAD request to the specified URL, which retrieves only the response headers without the body (30 second timeout, follows redirects).

Parameters:

Returns:

String -> Result String String

result = Curl.head-request "https://api.example.com/users/123"
match result
| Success _ -> print "Resource exists"
| Error msg -> print "Failed: ${msg}"

url-encode

URL-encodes a string for use in URLs.

Converts a string to URL-encoded format, replacing special characters with percent-encoded sequences (e.g., space becomes %20).

Parameters:

Returns:

String -> String

encoded = Curl.url-encode "hello world"
# Returns: "hello%20world"
query = "search=${Curl.url-encode user-input}"

url-decode

URL-decodes a string from URL encoding.

String -> String

is-reachable?

Checks if a URL is reachable.

String -> Bool

error-message

Returns human-readable error message for a curl error code.

Int -> String