Created
April 15, 2019 14:40
-
-
Save kidandcat/61265885cb00225722bf2c5b3e69b694 to your computer and use it in GitHub Desktop.
Server in Nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asynchttpserver, asyncdispatch, json | |
var server = newAsyncHttpServer() | |
proc handler(req: Request) {.async.} = | |
case req.url.path: | |
of "/hello-world": | |
let msg = %* {"message": "Hello World"} | |
let headers = newHttpHeaders([ | |
("Content-Type","application/json"), | |
("Access-Control-Allow-Origin","*") | |
]) | |
await req.respond(Http200, $msg, headers) | |
else: | |
await req.respond(Http404, "Not Found") | |
echo "Listening on port 4000" | |
waitFor server.serve(Port(4000), handler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment