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"] = "gillenecho 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've spent most of my career working with or at startups. I'm currently the Director of Product @ Ockam where I'm helping developers build applications and systems that are secure-by-design. It's time we started securely connecting apps, not networks.
Previously I led the Terraform product team @ HashiCorp, where we launched Terraform Cloud and set the stage for a successful IPO. Prior to that I was part of the Startup Team @ AWS, and earlier still an early employee @ Heroku. I've also invested in a couple of dozen early stage startups.
Previously I led the Terraform product team @ HashiCorp, where we launched Terraform Cloud and set the stage for a successful IPO. Prior to that I was part of the Startup Team @ AWS, and earlier still an early employee @ Heroku. I've also invested in a couple of dozen early stage startups.