Skip to content

Latest commit

 

History

History
83 lines (58 loc) · 2.41 KB

README.md

File metadata and controls

83 lines (58 loc) · 2.41 KB

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)};