• 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
FroMage / ceylon.net / 1.2.2
Ceylon Network Platform Module
Category SDK

The Ceylon SDK

Backends JVM
Maven coordinates
Compatible Ceylon release JVM: 1.2.x, 1.3.x (latest)
Published Mar 11, 2016
Stats Downloads (JVM): 1154
Source downloads: 850
Authors Matej Lazar
Stéphane Épardaud
License Apache Software License
Description

This module defines APIs for:

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

The ceylon.net.uri::Uri class supports connection to an HTTP URI. A new Uri may be obtained using ceylon.net.uri::parse.

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

A ceylon.net.http.server::Server represents a HTTP server. A new Server may be defined using ceylon.net.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));
}
Dependencies
ceylon.collection/1.2.2 shared
ceylon.file/1.2.2
ceylon.interop.java/1.2.2
ceylon.io/1.2.2 shared
ceylon.language/1.2.2
com.redhat.ceylon.module-resolver/1.2.2 shared
io.undertow.core/1.3.5.Final
java.base/7 JDK
org.jboss.xnio.api/3.3.2.Final
org.jboss.xnio.nio/3.3.2.Final
Usage
  • Import
 import ceylon.net "1.2.2";
Module links Members
Imported By
Home
Code repository
Issue tracker
Browse
Download .car
No .js archive
Download source archive
Download module documentation
View API documentation

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