vertx.http documentation
Provides a broad set of functions for creating HTTP servers and
clients, and handling requests.
add-trailer
(add-trailer req-or-resp key value)
Sets an HTTP trailer on a client request or server response.
Key can be a string, keyword, or symbol. The latter two will be
converted to a string via name. Returns the request or response.
add-trailers
(add-trailers req-or-resp trailers)
Sets a HTTP trailers on a client request or server response.
Keys can be strings, keywords, or symbols. The latter two will be
converted to strings via name. Returns the request or response.
client
(client)
(client properties)
Creates a HTTP or HTTPS client (HttpClient) instance from vertx.core/*vertx*.
properties is a map of properties to set on the newly created
client instance. They are translated into .setXXX calls by
camel-casing the keyword key. Example: {:key-store-path
"/some/path"} will trigger a call to .setKeyStorePath on the
client object. See the docuementation for
org.vertx.java.core.http.HttpClient for a full list of properties.
close
(close server)
(close server handler)
Close the server. Any open HTTP connections will be closed.
connect
(connect client uri handler)
Creates a CONNECT HttpClientRequest object.
uri is the relative portion of the url to be requested. If a full url is
provided, the host and port will be ignored, using the host and
port set on the client object instead. handler can either be a
single-arity fn or a Handler instance that will be passed the
HttpClientResponse. The request won't be issued until ended with
a call to the end function.
delete
(delete client uri handler)
Creates a DELETE HttpClientRequest object.
uri is the relative portion of the url to be requested. If a full url is
provided, the host and port will be ignored, using the host and
port set on the client object instead. handler can either be a
single-arity fn or a Handler instance that will be passed the
HttpClientResponse. The request won't be issued until ended with
a call to the end function.
end
(end req-or-resp)
(end req-or-resp content)
(end req-or-resp content enc)
Ends the server request or client response.
Writes the given content to the request or response before ending,
using the same rules as vertx.stream/write. If no data has been
written to the response body, the actual response won't get written
until this method gets called. Once the response has ended, it
cannot be used any more.
expect-multi-part
(expect-multi-part req)
Call this if you are expecting a multi-part form to be submitted in
the request. This must be called before the body of the request has
been received if you intend to call form-attributes.
get
(get client uri handler)
Creates a GET HttpClientRequest object.
uri is the relative portion of the url to be requested. If a full url is
provided, the host and port will be ignored, using the host and
port set on the client object instead. handler can either be a
single-arity fn or a Handler instance that will be passed the
HttpClientResponse. The request won't be issued until ended with
a call to the end function.
get-now
(get-now client uri handler)
(get-now client uri headers handler)
Creates a GET HttpClientRequest object.
uri is the relative portion of the url to be requested. If a full
url is provided, the host and port will be ignored, using the host
and port set on the client object instead. handler can either be a
single-arity fn or a Handler instance that will be passed the
HttpClientResponse. This is a quick version of the get function,
used when you don't need to write a body to the request. This
request is immediately issued, and the end function need not be
called.
head
(head client uri handler)
Creates a HEAD HttpClientRequest object.
uri is the relative portion of the url to be requested. If a full url is
provided, the host and port will be ignored, using the host and
port set on the client object instead. handler can either be a
single-arity fn or a Handler instance that will be passed the
HttpClientResponse. The request won't be issued until ended with
a call to the end function.
listen
(listen server port)
(listen server port host)
(listen server port host handler)
Tells the http-server to start listening for connections on port.
If host is not provided, it defaults to "0.0.0.0". handler can
either be a two-arity fn that will be passed the exception (if any)
and server from the result of the listen call, or a Handler
instance that will be called with the AsyncResult object that wraps
the exception and server. Returns the server instance.
Be aware this is an async operation and the server may not bound on
return of the function.
on-body
(on-body http handler)
Attach a handler to receive the entire body in one piece.
http can either be a server request or client response. handler
can either be a single-arity fn or a Handler instance that will be
passed the body as a buffer. This saves the user having to manually
set a data and end handler and append the chunks of the body until
the whole body received. Don't use this if your request body is
large - you could potentially run out of RAM. Returns the given
server request or client response.
on-continue
(on-continue req handler)
Registers a continue handler on a HttpClientRequest.
handler can either be a zero-arity fn or a Handler instance that
will be called when the server is ready to continue. If you send
an HTTP request with the Expect header set to the value
100-continue and the server responds with an interim HTTP response
with a status code of 100, then the handler will be called. You
can then continue to write data to the request body and later end
it.
on-request
(on-request server handler)
Attaches a request handler to the server.
As HTTP requests are received by the server, instances of
HttpServerRequest will be created and passed to this
handler. handler can either be a single-arity fn or a Handler
instance that will be passed the request object. Returns the server
instance.
on-upload
(on-upload req handler)
Set the upload handler on a server request.
The handler will get notified once a new file upload was received
and so allow to get notified by the upload in progress. handler can
either be a single-arity fn that will be passed a map of properties
of the uploaded file, or a Handler that will be called with the raw
HttpServerFileUpload object. See upload-file-info for more
information on the file properties. Returns the request.
options
(options client uri handler)
Creates a OPTIONS HttpClientRequest object.
uri is the relative portion of the url to be requested. If a full url is
provided, the host and port will be ignored, using the host and
port set on the client object instead. handler can either be a
single-arity fn or a Handler instance that will be passed the
HttpClientResponse. The request won't be issued until ended with
a call to the end function.
params
(params req)
Returns a map of parameters for the request.
Keys will be keywords, and keys that have multiple values in the
params will have those values stored as a vector.
patch
(patch client uri handler)
Creates a PATCH HttpClientRequest object.
uri is the relative portion of the url to be requested. If a full url is
provided, the host and port will be ignored, using the host and
port set on the client object instead. handler can either be a
single-arity fn or a Handler instance that will be passed the
HttpClientResponse. The request won't be issued until ended with
a call to the end function.
post
(post client uri handler)
Creates a POST HttpClientRequest object.
uri is the relative portion of the url to be requested. If a full url is
provided, the host and port will be ignored, using the host and
port set on the client object instead. handler can either be a
single-arity fn or a Handler instance that will be passed the
HttpClientResponse. The request won't be issued until ended with
a call to the end function.
put
(put client uri handler)
Creates a PUT HttpClientRequest object.
uri is the relative portion of the url to be requested. If a full url is
provided, the host and port will be ignored, using the host and
port set on the client object instead. handler can either be a
single-arity fn or a Handler instance that will be passed the
HttpClientResponse. The request won't be issued until ended with
a call to the end function.
remote-address
(remote-address req)
Returns the remote address from the request as {:host "127.0.0.1" :port 5566}.
request
(request client method uri handler)
Creates an HttpClientRequest object for the given HTTP method.
method should be one of: :OPTIONS, :GET, :HEAD, :POST, :PUT,
:DELETE, :TRACE, :CONNECT, or :PATCH. uri is the relative portion
of the url to be requested. If a full url is provided, the host and
port will be ignored, using the host and port set on the client
object instead. handler can either be a single-arity fn or a
Handler instance that will be passed the HttpClientResponse. The
request won't be issued until ended with a call to the end
function.
request-method
(request-method req)
Reads the HTTP request method from the request object as a keyword of the form :GET.
send-file
(send-file resp filename)
(send-file resp filename not-found)
Stream a file directly from disk to the outgoing connection.
not-found should be the path to a resource to serve if filename is
not found. If not-found is not specified, a standard 404 response
is generated. This bypasses userspace altogether where supported by
the underlying operating system. This is a very efficient way to
serve files. Returns the response object.
server
(server)
(server properties)
Creates a HTTP or HTTPS server (HttpServer) instance from vertx.core/*vertx*.
properties is a map of properties to set on the newly created
server instance. They are translated into .setXXX calls by
camel-casing the keyword key. Example: {:key-store-path
"/some/path"} will trigger a call to .setKeyStorePath on the
server object. See the docuementation for
org.vertx.java.core.http.HttpServer for a full list of properties.
server-response
(server-response req)
(server-response req properties)
Creates a response object for the given request object.
Properties is a map of options for the server instance. They are
translated into .setXXX calls by camel-casing the keyword
key. Example: {:status-code 418} will trigger a call to
.setStatusCode on the response object. See the docuementation for
org.vertx.java.core.http.HttpServerResponse for a full list of
properties.
trace
(trace client uri handler)
Creates a TRACE HttpClientRequest object.
uri is the relative portion of the url to be requested. If a full url is
provided, the host and port will be ignored, using the host and
port set on the client object instead. handler can either be a
single-arity fn or a Handler instance that will be passed the
HttpClientResponse. The request won't be issued until ended with
a call to the end function.
trailers
(trailers req-or-resp)
Returns a map of trailers for the server request or client response.
Keys will be keywords, and keys that have multiple values in the
trailers will have those values stored as a vector.
upload-file-info
(upload-file-info file)
Takes an HttpServerFileUpload object, and returns a map of properties about that object.
The properties are:
* :filename - the name of the file
* :name - the name of the upload attribute
* :content-type - the content-type specified in the upload
* :encoding - the content transfer encoding
* :size - the size of the file in bytes
* :charset - the Charset as a String
* :stream - the original file object, which is also a ReadStream
* :save-fn - a single-arity fn that can be passed a path to save the file to disk
version
(version req)
Reads the HTTP version from the request object as a String of the form "HTTP/1.1".