Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libcurlez

A C++ library wrapping libcurl's easy API, allowing you to easily perform synchronous HTTP queries.

Example

Simple query:

#include <libcurlez/curlez.hxx>
#include <iostream>

int main()
{
  Curl query;
  unsigned short status;

  query.url("http://google.fr")
       .follow_redirects();
  switch (status = query.perform())
  {
  case 0:
    std::cout << "CURL error: " << query.error() << std::endl;
    break ;
  default:
    std::cout << "Received status: " << status;
    break ;
  }
  return 0;
}

Reading response headers and body:

#include <libcurlez/curlez.hxx>
#include <iostream>

int main()
{
  CurlReader query;

  query.url("http://google.fr")
       .follow_redirects();
  if (query.perform() == 200)
  {
    std::cout << "Content-Type = " << query.response_header("Content-Type")
              << std::endl << "--" << std::endl
              << query.response_body() << std::endl;
    return 0;
  }
  return -1;
}

Sending queries with custom method, header and body:

#include <libcurlez/curlez.hxx>
#include <iostream>

int main()
{
  Curl query;

  query.method("PUT")
       .url("http://google.fr")
       .header("Content-Type", "application/json")
       .body("{ \"json\": 42 }")
       .follow_redirects();
  return query.perform() == 200;
}

Log curl stderr to a stream:

#include <libcurlez/curlez.hxx>
#include <iostream>

int main()
{
  Curl query;
  std::ostringstream stream;

  query.url("http://google.fr")
       .follow_redirects()
       .verbose(true)
       .stderr(stream)
       .perform();
  std::cout << "Curl logs:" << std::endl << stream.str() << std::endl;
  return 0;
}

About

c++ wrapper for libcurl's easy API

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages