Skip to content

Araq/libcurl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libcurl.nim

Nim wrapper for libcurl (v7.x)

libcurl v7.x

basic example

import libcurl

proc curlWriteFn(
  buffer: cstring,
  size: int,
  count: int,
  outstream: pointer): int =
  
  let outbuf = cast[ref string](outstream)
  outbuf[] &= buffer
  result = size * count
  
let webData: ref string = new string
let curl = easy_init()

discard curl.easy_setopt(OPT_USERAGENT, "Mozilla/5.0")
discard curl.easy_setopt(OPT_HTTPGET, 1)
discard curl.easy_setopt(OPT_WRITEDATA, webData)
discard curl.easy_setopt(OPT_WRITEFUNCTION, curlWriteFn)
discard curl.easy_setopt(OPT_URL, "http://localhost/")

let ret = curl.easy_perform()
if ret == E_OK:
  echo(webData[])

see also: https://curl.haxx.se/libcurl/c/example.html