Skip to content

Instantly share code, notes, and snippets.

@dom96
Created May 1, 2014 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dom96/49427cd0a9c8da47fff3 to your computer and use it in GitHub Desktop.
Save dom96/49427cd0a9c8da47fff3 to your computer and use it in GitHub Desktop.
import asynchttpserver, httpclient, parseurl, asyncdispatch, strtabs, strutils
var server = newAsyncHttpServer()
proc onRequest(req: TRequest) {.async.} =
var client = newAsyncHttpClient()
var htmlResp = ""
try:
let reqResp = await client.get(req.url.path)
htmlResp =
if reqResp.status.startsWith("200"): "It's up!"
else: "It's down :("
except EOS:
htmlResp = "It's down :("
let headers = {"Content-Type": "text/html"}
echo("Replying with: ", htmlResp)
await req.respond(Http200, htmlResp, headers.newStringTable)
server.serve(TPort(8080), onRequest)
runForever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment