summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhonewatson <hone@hone.be>2016-10-03 20:22:32 +1100
committerGitHub <noreply@github.com>2016-10-03 20:22:32 +1100
commit065210e6a3dd63087f7f57458745d272475ab449 (patch)
treea6b7f392741949a8dba091f80b6c4490d7e4fefa
parent6e1313515df4ee5808c77af5aeacfa77fce42474 (diff)
downloadNim-065210e6a3dd63087f7f57458745d272475ab449.tar.gz
Add respond proc example
Add an example for the respond proc demonstration JSON response.
-rw-r--r--lib/pure/asynchttpserver.nim11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/pure/asynchttpserver.nim b/lib/pure/asynchttpserver.nim
index a658097f9..bb85787a4 100644
--- a/lib/pure/asynchttpserver.nim
+++ b/lib/pure/asynchttpserver.nim
@@ -81,6 +81,17 @@ proc respond*(req: Request, code: HttpCode, content: string,
   ## content.
   ##
   ## This procedure will **not** close the client socket.
+  ##
+  ## Examples
+  ## --------
+  ## .. code-block::nim
+  ##    proc handler(req: Request) {.async.} =
+  ##      if $req.url.path == "/hello-world":
+  ##        let msg = %* {"message": "Hello World"}
+  ##        let headers = newHttpHeaders([("Content-Type","application/json")])
+  ##        await req.respond(Http200, $msg, headers)
+  ##      else:
+  ##        await req.respond(Http404, "Not Found")
   var msg = "HTTP/1.1 " & $code & "\c\L"
 
   if headers != nil: