Web API Request
Simple Recipe to query an API for JSON data.
Files
/package.nimble
# Package
version = "0.1.0"
author = "Jonathan Turnock"
description = "Simple API Client Example"
license = "MIT"
srcDir = "src"
bin = @["application"]
binDir = "dist"
# Dependencies
requires "nim >= 1.4.0"
/nim.cfg
-d:ssl
/src/application.nim
import httpclient
import strformat
import json
var client = newHttpClient()
when isMainModule:
var response = client.getContent("https://jsonplaceholder.typicode.com/todos/1")
var jsonResponse = parseJson(response)
var userId = jsonResponse["userId"]
var id = jsonResponse["id"]
var title = jsonResponse["title"]
echo response
echo fmt"userId: {userId}, id: {id}, title: {title}"