We are using asynchttpserver with asyncdispatch like this:
import asynchttpserver, asyncdispatch
var server = newAsyncHttpServer()
proc cb(req: Request) {.async.} =
await req.respond(Http200, "Hello World", newHttpHeaders())
waitFor server.serve(Port(8080), cb)
Is there a way to enable HTTPS for asynchttpserver? If there isn't, would there be another option?
I highly recommend instead of doing HTTPS with Nim, do it with either nginx or cloudflare. For HTTPS with Nim you need to get a certificate and that can be both costly $10/year for domain and $100/year for cert from some authority. You also need a way to keep it up to date. Pain....
With nginx, you can use letsEncrypt's certBot with a free cert and keep it up to date, then just proxy pass it to your normal HTTP nim server. Will probably take you 30 minutes to figure out. I do that right now.
Or you can use free tear of Cloudflare to just setup you up with cert provided you have a domain name. Just a couple clicks and you are done. Will probably take you 10 minutes to figure out. I do that right now too.
Nim sockets have TLS support. With asynchttpserver specifically, if you locally patch the socket field in AsyncHttpServer to be public, maybe something like the following could work:
import asynchttpserver, net
var server = newAsyncHttpServer()
let ctx = newContext(certFile = "cert.pem", keyFile = "key.pem")
ctx.wrapSocket(server.socket)
https://github.com/status-im/nim-chronos/ comes with a HTTP server with built-in SSL support - it's also really simple to get started with, as it builds the necessary SSL support as part of your application (no need for OpenSSL libraries).
We've been using it in production with good results.
For embedded I would recommend just wrapping the C web
Now I need to learn not only Nim but how to wrap C code in Nim.
AsyncHttpServer isn't suited for embedded
What do you mean? This is an arm64 platform with Linux.
I wouldn't run it "bare" without a reverse proxy anyway.
So, what is it for? It seems there is a very narrow use of AsyncHttpServer.