The HTTP-CLIENT library#
The HTTP-CLIENT module#
Requests#
- http-request Sealed Generic function#
Perform a complete HTTP request and response.
- Signature:
http-request (request-method url #key headers parameters content follow-redirects stream) => (response)
- Parameters:
request-method – An instance of
<byte-string>
url – A string or a URI.
headers (#key) – A
<table>
of strings mapping header names to values.parameters (#key) – A
<table>
of strings mapping query parameter names to values.content (#key) – An instance of
<string>
or<table>
. If given a<table>
it will be converted to application/x-www-urlencoded-form.follow-redirects (#key) – A
<boolean>
or<integer>
. If an integer, this is the maximum number of redirects to follow.#t
means no limit.stream (#key) – A stream to which response content will be copied. If this is provided the response data will not be stored in the
response-content
slot.
- Values:
response – An instance of
<http-response>
.
- http-delete Constant#
Convenience function for performing a DELETE request, equivalent to curry(http-request, “DELETE”).
- http-get Constant#
Convenience function for performing a GET request, equivalent to curry(http-request, “GET”).
- http-head Constant#
Convenience function for performing a HEAD request, equivalent to curry(http-request, “HEAD”).
- http-options Constant#
Convenience function for performing an OPTIONS request, equivalent to curry(http-request, “OPTIONS”).
- http-post Constant#
Convenience function for performing a POST request, equivalent to curry(http-request, “POST”).
- http-put Constant#
Convenience function for performing a PUT request, equivalent to curry(http-request, “PUT”).
- send-request Generic function#
Send an HTTP request over an existing connection. This is a low-level API.
- Signature:
send-request (conn request-method url #rest start-request-args #key content #all-keys) => ()
- Parameters:
conn – An instance of
<http-connection>
.request-method – An instance of
<byte-string>
.url – An instance
<string>
or<uri>
.start-request-args (#rest) – An instance of
<object>
.content (#key) – An instance of
<byte-string>
.
- start-request Generic function#
Send the request line and request headers over an existing connection but do not send any content. This is a low-level API.
- Signature:
start-request (conn request-method url #key headers standard-headers http-version) => ()
- Parameters:
conn – An instance of
<http-connection>
.request-method – An instance of
<byte-string>
.url – An instance
<string>
or<uri>
.headers (#key) – An instance of
<object>
.standard-headers (#key) – An instance of
<object>
.http-version (#key) – An instance of
<byte-string>
.
- finish-request Generic function#
Finish sending a request over an existing connection by, for example, sending a zero-length chunk in a chunked request. This is a low-level API.
- Signature:
finish-request (conn) => ()
- Parameters:
conn – An instance of
<http-connection>
.
Responses#
- <http-response> Open Primary Class#
All HTTP requests result in an instance of this class being created.
- Superclasses:
<chunking-input-stream>
,<base-http-response>
,<message-headers-mixin>
- Init-Keywords:
content –
- read-response Open Generic function#
Read the content of a response from an existing connection after headers have already been read. This is a low-level API.
- Signature:
read-response (conn #key read-content response-class) => (response)
- Parameters:
conn – An instance of
<http-connection>
.read-content (#key) – An instance of
<boolean>
.response-class (#key) – A subclass of
<http-response>
. The default is<http-response>
.
- Values:
response – An instance of
<http-response>
.
- response-content Generic function#
Fetch the content of a response from a
<http-response>
.- Signature:
response-content (response) => (content)
- Parameters:
response – An instance of
<http-response>
.
- Values:
content –
#f
or an instance of<byte-string>
.
Errors#
- <maximum-redirects-exceeded> Open Class#
Signaled when an HTTP request results in too many redirects, based on the
follow-redirects:
keyword argument.- Superclasses:
- <redirect-loop-detected> Open Class#
Signaled when an HTTP request results in a redirect loop.
- Superclasses:
Connections#
- with-http-connection Macro#
Open an HTTP connection and keep it open by automatically adding “Connection: Keep-alive” headers. For most uses, this should be the only connection-related API needed.
Example:
with-http-connection (conn = "opendylan.org", port: 80, outgoing-chunk-size: 8192) send-request(conn, "GET", "/") let response :: <http-response> = read-response(conn); ...content is in response.response-content... send-request(conn, "POST", "/blah", content: "..."); let response :: <http-response> = read-response(conn); ... end;
Note that the port and outgoing-chunk-size specified above are the default values. It is also possible to supply a
<uri>
instead of a hostname and port number:with-http-connection (conn = uri) ... end
- <http-connection> Open Class#
- Superclasses:
<basic-stream>:streams:io
- Init-Keywords:
host –
outgoing-chunk-size –
- connection-host Generic function#
- connection-port Generic function#
- make-http-connection Function#
- note-bytes-sent Open Generic function#
- Signature:
note-bytes-sent (conn byte-count) => (#rest results)
- Parameters:
conn – An instance of
<http-connection>
.byte-count – An instance of
<integer>
.
- Values:
#rest results – An instance of
<object>
.
- outgoing-chunk-size Generic function#
Miscellaneous#
- *http-client-log* Variable#