Araq / libcurl

Nim wrapper for libcurl.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Nim wrapper for libcurl.

License:MIT License


Languages

Language:Nim 100.0%