Nim: How to make a HTTP POST request

Mar 21, 2022

To post to an endpoint simulating a form-data response:

var client = newHttpClient()
var data = newMultipartData()
data["first_name"] = "glenn"
data["last_name"] = "gillen

echo client.postContent("https://some.api", multipart=data)

If instead you need to post a JSON object:

import std/[httpclient, json]

let client = newHttpClient()
client.headers = newHttpHeaders({ "Content-Type": "application/json" })
let body = %*{
    "first_name": "glenn",
    "last_name": "gillen
}
let response = client.request("http://some.api", httpMethod = HttpPost, body = $body)
echo response.status
Hi, I'm Glenn! 👋 I'm currently Director of Product (Terraform) @ HashiCorp, and we're hiring! If you'd like to come and work with me and help make Terraform Cloud even more amazing we have multiple positions opening in Product ManagementDesign, and Engineering & Engineering Management across a range of levels (i.e., junior through to senior). Please send in an application ASAP so we can get in touch.