Nim: Making a HTTP GET request

Mar 21, 2022

Get requests in Nim are fairly straight-forward:

import std/httpclient
var client = newHttpClient()
echo client.getContent("https://google.com")

Nim also supports async requests, so to do the same but asynchronously:

import std/[asyncdispatch, httpclient]

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

echo waitFor asyncProc()
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.