from ucall import HTTPStatus, Interface, Library, Request, Server
def hello(var request: Request) raises:
request^.reply(HTTPStatus.OK, "Hello!".as_bytes())
def echo(var request: Request) raises:
var body = List[Byte](capacity=len(request.body()))
body.extend(request.body()) # a reply consumes the request its body borrows from
request^.reply(HTTPStatus.OK, body)
def main() raises:
var server = Server(Library(), [Interface("127.0.0.1:8545")])
server.get["/hello", hello]()
server.post["/echo", echo]()
server.take_calls(0) # until server.stop() from a handler or another threadLibrary() opens the shared object once, and every server, client and response created through it keeps it mapped.