mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-02 01:48:00 +00:00
New runnableExample for newAsyncHttpClient() (#14045)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user