This module defines APIs for:

  • representing and manipulating URIs,
  • connecting to HTTP servers, and
  • defining HTTP endpoints and executing HTTP servers.

The Uri class supports connection to an HTTP URI. A new Uri may be obtained using parse().

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

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.net.http
ceylon.net.http.client

HTTP client APIs.

ceylon.net.http.server

A HTTP server.

ceylon.net.http.server.endpoints

Predefined HTTP endpoint implementations for serving static files and HTTP redirection.

ceylon.net.http.server.websocket
ceylon.net.uri

An API for constructing and parsing URIs.

Dependencies
ceylon.collection1.2.0
ceylon.file1.2.0
ceylon.interop.java1.2.0
ceylon.io1.2.0
io.undertow.core1.1.3.Final
java.base8
org.jboss.xnio.api3.3.0.Final
org.jboss.xnio.nio3.3.0.Final