• Modules
    • By category
    • By name
    • Most popular
    • Most downloaded
    • Repository
  • Register
  • Log in
  • Help
    • Start using Ceylon Herd
    • Publish your first module
    • Module publishing guidelines
    • All about Ceylon
    • Keyboard Shortcuts

    • s Focus search module bar
      ? Open this information panel
      j Move selection down
      k Move selection up
      enter Open current selection
Module info
Name
quintesse / ceylon.http.server
Ceylon Http Server Platform Module
Description

This module defines APIs for defining HTTP endpoints and executing HTTP servers.

A ceylon.http.server::Server represents a HTTP server. A new Server may be defined using ceylon.http.server::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));
}
Category SDK

The Ceylon SDK

Last Published Aug 21, 2017
Stats Downloads (JVM): 12561
Downloads (JS): 0
Source downloads: 1933
Module links Home
Code repository
Issue tracker
Imported By
Browse
List of published versions
1.3.3 JVM JVM: 1.2.x, 1.3.x (latest) Published Aug 21, 2017 Browse
View docs
1.3.2 JVM JVM: 1.2.x, 1.3.x (latest) Published Mar 1, 2017 Browse
View docs
1.3.1 JVM JVM: 1.2.x, 1.3.x (latest) Published Nov 21, 2016 Browse
View docs
1.3.0 JVM JVM: 1.2.x, 1.3.x (latest) Published Sep 15, 2016 Browse
View docs
You must be logged in to comment.

Ceylon Herd v1.24 Copyright 2012-2022 Red Hat. About