From 1a44b7e3ced0e2d092f2c607d61a6b28c1ca339c Mon Sep 17 00:00:00 2001 From: Tristram Oaten Date: Tue, 21 Apr 2020 13:47:06 +0100 Subject: [PATCH] New runnableExample for `newAsyncHttpClient()` (#14045) --- lib/pure/httpclient.nim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index 5d44fce7aa..a1a2d91295 100644 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -573,6 +573,17 @@ proc newHttpClient*(userAgent = defUserAgent, maxRedirects = 5, ## ``TimeoutError`` is raised. ## ## ``headers`` specifies the HTTP Headers. + runnableExamples: + import asyncdispatch, httpclient, strutils + + proc asyncProc(): Future[string] {.async.} = + var client = newAsyncHttpClient() + return await client.getContent("http://example.com") + + let exampleHtml = waitFor asyncProc() + assert "Example Domain" in exampleHtml + assert not ("Pizza" in exampleHtml) + new result result.headers = headers result.userAgent = userAgent