This module defines APIs for defining HTTP endpoints and executing HTTP servers.
A Server
represents a HTTP
server. A new Server
may be defined using
newServer()
.
void runServer() { //create a HTTP server value server = newServer { //an endpoint, on the path /hello Endpoint { path = startsWith("/hello"); //handle requests to this path service(Request request, Response response) => response.writeString("hello world"); }, WebSocketEndpoint { path = startsWith("/websocket"); onOpen(WebSocketChannel channel) => print("Channel opened"); onClose(WebSocketChannel channel, CloseReason closeReason) => print("Channel closed"); void onError(WebSocketChannel webSocketChannel, Exception? throwable) {} void onText(WebSocketChannel channel, String text) { print("Received text:"); print(text); channel.sendText(text.uppercased); } void onBinary(WebSocketChannel channel, ByteBuffer binary) { String data = utf8.decode(binary); print("Received binary:"); print(data); value encoded = utf8.encode(data.uppercased); channel.sendBinary(encoded); } } }; //start the server on port 8080 server.start(SocketAddress("127.0.0.1",8080)); }
Packages | |
ceylon.http.server | A HTTP server. T |
ceylon.http.server.endpoints | Predefined HTTP endpoint implementations for serving static files and HTTP redirection. |
ceylon.http.server.websocket |
Dependencies | ||
ceylon.collection | 1.3.2 | |
ceylon.file | 1.3.2 | |
ceylon.http.common | 1.3.2 | |
ceylon.interop.java | 1.3.2 | |
ceylon.io | 1.3.2 | |
com.redhat.ceylon.module-resolver | 1.3.2 | |
io.undertow.core | 1.4.4.Final | |
java.base | 7 | |
org.jboss.xnio.nio | 3.3.6.Final |
A HTTP server. This package defines the API for creating a new server and defining endpoints using:
Endpoint
for synchronously processed endpoints,AsynchronousEndpoint
for asynchronously processed
endpoints, andWebSocketEndpoint
for web socket endpoints.See ceylon.http.server.endpoints
for
predefined covenience endpoints for
serving static files
and HTTP redirection.
Values | |
started | Source Codeshared started started |
starting | Source Codeshared starting starting |
stopped | Source Codeshared stopped stopped |
stopping | Source Codeshared stopping stopping |
Functions | |
endsWith | Source Codeshared Matcher endsWith(String suffix) Rule using |
equals | Source Codeshared Matcher equals(String path) Rule using |
isRoot | Source Codeshared Matcher isRoot() Rule matching / (root). |
newServer | Source Codeshared Server newServer({HttpEndpoint|WebSocketBaseEndpoint*} endpoints) Create a new HTTP server. |
startsWith | Source Codeshared Matcher startsWith(String prefix) Rule using |
template | Source Codeshared TemplateMatcher template(String template) |
Interfaces | |
Request | Source Codeshared Request Defines an object to provide client request information to a web endpoint. |
Response | Source Codeshared Response An object to assist sending response to the client. |
Server | Source Codeshared Server A HTTP server. |
Session | Source Codeshared Session An object representing a session between a server and a client. |
Classes | |
AsynchronousEndpoint | Source Codeshared AsynchronousEndpoint Asynchronous web endpoint. Endpoint is executed
asynchronously. End of request processing must be
signaled by calling |
Endpoint | Source Codeshared Endpoint Synchronous web endpoint. |
EndpointBase | Source Codeshared abstract EndpointBase |
HttpEndpoint | Source Codeshared abstract HttpEndpoint |
Matcher | Source Codeshared abstract Matcher |
Options | Source Codeshared Options Options for starting a |
Status | Source Codeshared abstract Status The status of a |
TemplateMatcher | Source Codeshared TemplateMatcher Matcher to leverage Undertow's template mechanism for path templates and path parameters. It should be given to an Endpoint without combining it with other matchers. Matches a path with path parameters. The parameters are indicated by curly braces in the template, for example /a/{b}/c/{d} Their values can be obtained from the Request via the Request.pathParameter() method. |
UploadedFile | Source Codeshared UploadedFile |
started | Source Codeshared started |
starting | Source Codeshared starting |
stopped | Source Codeshared stopped |
stopping | Source Codeshared stopping |
Exceptions | |
InternalException | Source Codeshared InternalException |
ServerException | Source Codeshared ServerException |