Source Code

This module allows you to represent URIs, to connect to HTTP servers and to run a HTTP server.

Sample usage for getting the contents of an HTTP URI:

void getit(String uriAsString){
    URI uri = parseURI(uriAsString);
    Request request = uri.get();
    Response response = request.execute();
    print(response.contents);
}

Sample usage for running a HTTP server:

void runServer() {
    //create a HTTP server
    value server = createServer {
        //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 = void (WebSocketChannel channel) { print("server: Channel opened."); };
            onClose = void (WebSocketChannel channel, CloseReason closeReason) { print("server: Channel closed."); };
            onError = void (WebSocketChannel webSocketChannel, Exception? throwable) {};
            onText = void (WebSocketChannel channel, String text) {
                print("Server received:");
                print(text);
                channel.sendText(text.uppercased);
            };
            onBinary = void (WebSocketChannel channel, ByteBuffer binary) {
                String data = utf8.decode(binary);
                print("Server received binary message:");
                print(data);
                value encoded = utf8.encode(data.uppercased);
                channel.sendBinary(encoded);
            };
        }
    };

    //start the server on port 8080
    server.start(8080);
}
By: Stéphane Épardaud, Matej Lazar
License: Apache Software License
Packages
ceylon.net.http
ceylon.net.http.client

Contains HTTP-specific stuff

ceylon.net.http.server

Ceylon web server.

ceylon.net.http.server.endpoints

Package contains predefined web endpoint implementations.

ceylon.net.http.server.websocket
ceylon.net.uri
Dependencies
ceylon.collection0.6
ceylon.file0.6
ceylon.io0.6
io.undertow.core1.0.0.Beta8
java.base7
org.jboss.logging3.1.2.GA
org.jboss.xnio.api3.1.0.CR6
org.jboss.xnio.nio3.1.0.CR6