Closed inkytonik closed 1 year ago
Just my initial thoughts of what we could aim for:
{
type Api = {
hello : (String) String
}
fun (port: Server(Api)) {
port.start({
hello = fun (name : String) => "Hello, " + name + "!"
})
}
}
From the programmer's perspective:
type Server = fun (A : Type) => { start : (A) Unit }
The type parameter A
is a record that contains all the required endpoints.
The start
method starts a HTTP server on the port specified by the corresponding command-line argument. The (function) argument to start
specifies the functionality of each endpoint. start
will not return unless the server terminates.
One implementation challenge is how the IR code will look. When a request is received, a function needs to be invoked. It is not entirely clear to me how this will work.
I currently have it so that the following program:
fun (server : HttpServer) server.start()
…will start a HTTP server on the port specified by the user. The server will always respond with Hello, world!
. The server (and the program) can be terminated by pressing the return key.
I'm using the Java HTTP server in the com.sun.net
package, which is almost as primitive as it gets. I worry that higher-level libraries will simply prove to be a nuisance given the intricacies of having the Cooma interpreter running a HTTP server.
Now for the tricky part of getting the server to run Cooma code…
Closed by #82
Allow applications to accept HTTP requests on a port supplied as a capability argument.