diff options
author | Alpha Shuro <alphashuro@gmail.com> | 2016-10-12 13:58:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-12 13:58:34 +0200 |
commit | 72b15678a1f66a8683034e30fefa51969a7ac4d5 (patch) | |
tree | 708c173d167e0d0f094c37cffb1d410d25bf4355 /lib | |
parent | e6ff6dd9c89b3156fe50f61f6a28bcaba4aca91c (diff) | |
download | Nim-72b15678a1f66a8683034e30fefa51969a7ac4d5.tar.gz |
Add example for posting json content
i struggled to figure out how to post json content with nim's http client. this is a fundamental capability in many web apps, we don't always need to send data as multipart form data (e.g. when communicating via json apis) so frankly i'm surprised it isn't part of the "post" and "postContent" procs
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/httpclient.nim | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index 4404a9426..bfeb9a52e 100644 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -50,6 +50,20 @@ ## ## echo client.postContent("http://validator.w3.org/check", multipart=data) ## +## You can also make post requests with custom headers. +## This example sets ``Content-Type`` to ``application/json`` +## and uses a json object for the body +## +## .. code-block:: Nim +## import httpclient, json +## +## let client = newHttpClient() +## client.headers = newHttpHeaders({ "Content-Type": "application/json" }) +## let body = %*{ +## "data": "some text" +## } +## echo client.request("http://some.api", httpMethod = HttpPost, body = $body) +## ## Progress reporting ## ================== ## |