Skip to content

Commit

Permalink
Fix broken async httpclient example
Browse files Browse the repository at this point in the history
As the async httpclient is almost certainly the first async example beginners will want to try, we OWE it to them to give them a real example.

Example repeated here for clarity:

```nim
import asyncdispatch, httpclient

proc asyncProc(): Future[string] {.async.} =
  var client = newAsyncHttpClient()
  return await client.getContent("http://example.com")

echo waitFor asyncProc()
```

This is my first Nim contribution, please let me know if the code is right. (it runs on my machine, but may not be the best example)
  • Loading branch information
0atman authored and dom96 committed Apr 20, 2020
1 parent 67d71bb commit 42a6424
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/pure/httpclient.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@
## ``AsyncHttpClient``:
##
## .. code-block:: Nim
## import httpClient
## import asyncdispatch, httpclient
##
## proc asyncProc(): Future[string] {.async.} =
## var client = newAsyncHttpClient()
## echo await client.getContent("http://google.com")
## return await client.getContent("http://example.com")
##
## echo waitFor asyncProc()
##
## The functionality implemented by ``HttpClient`` and ``AsyncHttpClient``
## is the same, so you can use whichever one suits you best in the examples
## shown here.
##
## **Note:** You will need to run asynchronous examples in an async proc
## **Note:** You need to run asynchronous examples in an async proc
## otherwise you will get an ``Undeclared identifier: 'await'`` error.
##
## Using HTTP POST
Expand Down

0 comments on commit 42a6424

Please sign in to comment.