Source Code

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));
}
Platform: Java
By: Stéphane Épardaud, Matej Lazar
License: Apache Software License
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.collection1.3.3
ceylon.file1.3.3
ceylon.http.common1.3.3
ceylon.io1.3.3
com.redhat.ceylon.module-resolver1.3.3
io.undertow.core1.4.4.Final
java.base7
org.jboss.xnio.nio3.3.6.Final

A HTTP server. This package defines the API for creating a new server and defining endpoints using:

See ceylon.http.server.endpoints for predefined covenience endpoints for serving static files and HTTP redirection.

By: Matej Lazar
Values
startedSource Codeshared started started
startingSource Codeshared starting starting
stoppedSource Codeshared stopped stopped
stoppingSource Codeshared stopping stopping
Functions
endsWithSource Codeshared Matcher endsWith(String suffix)

Rule using String.endsWith().

equalsSource Codeshared Matcher equals(String path)

Rule using String.equals().

isRootSource Codeshared Matcher isRoot()

Rule matching / (root).

newServerSource Codeshared Server newServer({HttpEndpoint|WebSocketBaseEndpoint*} endpoints)

Create a new HTTP server.

startsWithSource Codeshared Matcher startsWith(String prefix)

Rule using String.startsWith().

templateSource Codeshared TemplateMatcher template(String template)
Interfaces
RequestSource Codeshared Request

Defines an object to provide client request information to a web endpoint.

ResponseSource Codeshared Response

An object to assist sending response to the client.

ServerSource Codeshared Server

A HTTP server.

SessionSource Codeshared Session

An object representing a session between a server and a client.

Classes
AsynchronousEndpointSource Codeshared AsynchronousEndpoint

Asynchronous web endpoint. Endpoint is executed asynchronously. End of request processing must be signaled by calling complete().

EndpointSource Codeshared Endpoint

Synchronous web endpoint.

EndpointBaseSource Codeshared abstract EndpointBase
HttpEndpointSource Codeshared abstract HttpEndpoint
MatcherSource Codeshared abstract Matcher
OptionsSource Codeshared Options

Options for starting a Server.

StatusSource Codeshared abstract Status

The status of a Server.

TemplateMatcherSource 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.

UploadedFileSource Codeshared UploadedFile
startedSource Codeshared started
startingSource Codeshared starting
stoppedSource Codeshared stopped
stoppingSource Codeshared stopping
Exceptions
InternalExceptionSource Codeshared InternalException
ServerExceptionSource Codeshared ServerException