New runnableExample for newAsyncHttpClient() (#14045)

This commit is contained in:
Tristram Oaten
2020-04-21 13:47:06 +01:00
committed by GitHub
parent 7beed44fc9
commit 1a44b7e3ce

View File

@@ -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