inkytonik / cooma

The Cooma project is investigating secure programming language design based on fine-grained object capabilities.
Mozilla Public License 2.0
3 stars 2 forks source link

Add API server capability #80

Closed inkytonik closed 1 year ago

inkytonik commented 2 years ago

Allow applications to accept HTTP requests on a port supplied as a capability argument.

nhweston commented 2 years 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.

nhweston commented 2 years ago

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…

inkytonik commented 1 year ago

Closed by #82