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:
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:
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:
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:

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:
Values:
response-content Generic function#

Fetch the content of a response from a <http-response>.

Signature:

response-content (response) => (content)

Parameters:
Values:

Errors#

<maximum-redirects-exceeded> Open Class#

Signaled when an HTTP request results in too many redirects, based on the follow-redirects: keyword argument.

Superclasses:

<http-error>

<redirect-loop-detected> Open Class#

Signaled when an HTTP request results in a redirect loop.

Superclasses:

<http-error>

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#
Signature:

connection-host (object) => (#rest results)

Parameters:
Values:
  • #rest results – An instance of <object>.

connection-port Generic function#
Signature:

connection-port (conn) => (#rest results)

Parameters:
Values:
  • #rest results – An instance of <object>.

make-http-connection Function#
Signature:

make-http-connection (host-or-url #rest initargs #key port #all-keys) => (#rest results)

Parameters:
  • host-or-url – An instance of <object>.

  • initargs (#rest) – An instance of <object>.

  • port (#key) – An instance of <object>.

Values:
  • #rest results – An instance of <object>.

note-bytes-sent Open Generic function#
Signature:

note-bytes-sent (conn byte-count) => (#rest results)

Parameters:
Values:
  • #rest results – An instance of <object>.

outgoing-chunk-size Generic function#
Signature:

outgoing-chunk-size (object) => (#rest results)

Parameters:
Values:
  • #rest results – An instance of <object>.

outgoing-chunk-size-setter Generic function#
Signature:

outgoing-chunk-size-setter (value object) => (#rest results)

Parameters:
Values:
  • #rest results – An instance of <object>.