Skip to content

Minimal header only HTTP request library that wraps curl_easy_* functions using modern-ish C++.

License

Notifications You must be signed in to change notification settings

ptrks/easyhttp-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

easyhttp-cpp

Build Status

Overview

The goal of this library was to have a minimal CURL wrapper implementation that allowed users to make HTTP requests through configurable and reusable objects. These configurable requests could be individual HTTP calls that are responsible for interacting with different external RESTful API endpoints or services.

Additionally, basing it on CURL makes keeps it lightweight and fairly straghtforward to extend or modify.


Functionality

HTTP GET
Description Supported
Query Parameters ✔️
Custom Header ✔️
Custom Timeout ✔️
HTTP Basic Authentication ✔️
HTTP POST
Description Supported
Query Parameters ✔️
Custom Header ✔️
Custom Timeout ✔️
HTTP Basic Authentication ✔️
HTTP PUT

In Progress

HTTP DELETE

In Progress

HTTP PATCH

In Progress


Usage

Getting started is as easy as including easyhttp.hpp in your source file.

You probably want to create a RequestConfig object to store all relevant settings for your particular HTTP request:

struct RequestConfig {
  std::string url;
  UrlParameters params;
  Headers headers;
  BasicAuthentication auth;
  std::chrono::seconds timeout_sec;
};

Making a basic GET request

Explicit construction of a request configuration object showing available settings:

Request req = Request();
RequestConfig config = { "http://postman-echo.com/get", UrlParameters(), Headers(), BasicAuthentication(), std::chrono::seconds(1) };
RequestResponse resp = req.get(config);
std::cout << "Status: " << resp.status << " Content: " << resp.content << "\n";

Implict RequestConfig object with no settings besides URL and timeout of 3 seconds

Request req = Request();
RequestConfig config = { "http://google.com", {}, {}, {}, std::chrono::seconds(3) };
RequestResponse resp = req.get(config);

RequestConfig with URL paramaters foo:bar and timeout of 1 second

RequestConfig r = { "http://postman-echo.com/get", {{"foo","bar"}}, {}, {}, std::chrono::seconds(1)};

About

Minimal header only HTTP request library that wraps curl_easy_* functions using modern-ish C++.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published