techempower.nim 517 B

12345678910111213141516171819
  1. import options, asyncdispatch, json
  2. import httpbeast
  3. proc onRequest(req: Request): Future[void] =
  4. if req.httpMethod == some(HttpGet):
  5. case req.path.get()
  6. of "/json":
  7. var data = $(%*{"message": "Hello, World!"})
  8. const headers = "Content-Type: application/json"
  9. req.send(Http200, data, headers)
  10. of "/plaintext":
  11. const data = "Hello, World!"
  12. const headers = "Content-Type: text/plain"
  13. req.send(Http200, data, headers)
  14. else:
  15. req.send(Http404)
  16. run(onRequest)