New runnableExample for newAsyncHttpClient() (#14045)

This commit is contained in:
Tristram Oaten 2020-04-21 13:47:06 +01:00 • committed by GitHub
commit 1a44b7e3ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -573,6 +573,17 @@ proc newHttpClient*(userAgent = defUserAgent, maxRedirects = 5,
## ``TimeoutError`` is raised. ## ``TimeoutError`` is raised.
## ##
## ``headers`` specifies the HTTP Headers. ## ``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 new result
result.headers = headers result.headers = headers
result.userAgent = userAgent result.userAgent = userAgent