GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - jfayot/Http: A header-only HTTP library based on boost::beast and nlohmann::json

BranchesTags
Open more actions menu

Latest commit

 

History

23 Commits
23 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
include/Http
include/Http
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
CMakeLists.txt
CMakeLists.txt
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
codecov.yaml
codecov.yaml
 
 
package-lock.cmake
package-lock.cmake
 
 

Repository files navigation

HTTP library

A header-only HTTP client library based on boost::beast and nlohmann::json.

License: MIT

codecov Windows Build Status

Features

  • GET, PUT, POST, PATCH and DELETE resources from/to a REST service
  • HTTP/HTTPS
  • Basic and Bearer token authentication
  • Post FormData
  • Asynchronous response wrapped into future
  • Upload/Download files

Dependencies

  • OpenSSL (through openssl-cmake)
  • Boost::beast
  • Boost::uuid
  • nlohmann::json
  • fmtlib::fmt

All dependencies are pulled and compiled thanks to CPM.cmake

For Windows platform, you'll need to have NASM installed and your PATH pointing at it to build OpenSSL correctly.

Build

Use cmake to configure, build and install:

cmake -B build -DCMAKE_INSTALL_PREFIX=<your_install_dir>
cmake --build build --target install

Include directly into your project

Use CPM.cmake to include directly into your project:

cmake_minimum_required(VERSION 3.16)

project(your_project
  LANGUAGES CXX
)

# download CPM.cmake
file(
  DOWNLOAD
  https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.40.2/CPM.cmake
  ${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
  EXPECTED_HASH SHA256=c8cdc32c03816538ce22781ed72964dc864b2a34a310d3b7104812a5ca2d835d
)

include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)

CPMAddPackage("gh:jfayot/[email protected]")

add_executable(your_target ${CMAKE_CURRENT_LIST_DIR}/main.cpp)

target_link_libraries(your_target PRIVATE Http::client)

Minimal example

#include "Http/HttpTypes.hpp"
struct Person
{
  std::string name;
  int age;
  NLOHMANN_DEFINE_TYPE_INTRUSIVE(Person, name, age)
};

int main()
{
  Person person{ "captain", 42 };
  Http::Client client{ "http://127.0.0.1:8080" };
  Http::Request request = client.post("/persons").body(person);
  std::shared_future<Http::Response> future = request.send();

  // Do whatever needed
  // ...

  Http::Response res = future.get();

  if (true == res.ok())
  {
    Person content = res.body().get<Person>();
  }

  return 0;
}

About

A header-only HTTP library based on boost::beast and nlohmann::json

Topics

beastboostclienthttpnlohmann-jsonrest

Resources

Readme
MIT license
Activity

Stars

3 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.