All Projects → avocadoboi → cpp20-internet-client

avocadoboi / cpp20-internet-client

Licence: MIT license
An HTTP(S) client library for C++20.

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to cpp20-internet-client

Beetlex
high performance dotnet core socket tcp communication components, support TLS, HTTP, HTTPS, WebSocket, RPC, Redis protocols, custom protocols and 1M connections problem solution
Stars: ✭ 802 (+2258.82%)
Mutual labels:  socket, https
RRQMSocket
TouchSocket是.Net(包括 C# 、VB.Net、F#)的一个整合性的、超轻量级的网络通信框架。包含了 tcp、udp、ssl、http、websocket、rpc、jsonrpc、webapi、xmlrpc等一系列的通信模块。一键式解决 TCP 黏分包问题,udp大数据包分片组合问题等。使用协议模板,可快速实现「固定包头」、「固定长度」、「区间字符」等一系列的数据报文解析。
Stars: ✭ 286 (+741.18%)
Mutual labels:  socket, https
Python Mocket
a socket mock framework - for all kinds of socket animals, web-clients included
Stars: ✭ 209 (+514.71%)
Mutual labels:  socket, https
Hp Socket
High Performance TCP/UDP/HTTP Communication Component
Stars: ✭ 4,420 (+12900%)
Mutual labels:  socket, https
Tcpprobe
Modern TCP tool and service for network performance observability.
Stars: ✭ 207 (+508.82%)
Mutual labels:  socket, https
Oksocket
An blocking socket client for Android applications.
Stars: ✭ 2,359 (+6838.24%)
Mutual labels:  socket
Node Websocket Chatroom
web聊天室项目
Stars: ✭ 227 (+567.65%)
Mutual labels:  socket
Blockchain
A simple implementation of blockchain in java
Stars: ✭ 201 (+491.18%)
Mutual labels:  socket
Zserver4d
ZServer4D 是一套从商业项目剥离而出的云服务器中间件,可以承载百万级的分布式负载服务,并且支持IoT及内网穿透
Stars: ✭ 199 (+485.29%)
Mutual labels:  socket
Delphi Cross Socket
Delphi cross platform socket library
Stars: ✭ 250 (+635.29%)
Mutual labels:  socket
Baselibrary
🔥Android开发 常用基础公共库(mvp/mvvm/retrofit/rxjava/socket/ble/多语言) 直接下载或依赖即可使用
Stars: ✭ 243 (+614.71%)
Mutual labels:  socket
Simplenetwork
simple TCP server / client C++ linux socket
Stars: ✭ 225 (+561.76%)
Mutual labels:  socket
Ohsce
PHP HI-REL SOCKET TCP/UDP/ICMP/Serial .高可靠性PHP通信&控制框架SOCKET-TCP/UDP/ICMP/硬件Serial-RS232/RS422/RS485 AND MORE!
Stars: ✭ 206 (+505.88%)
Mutual labels:  socket
Node Decorators
node-decorators
Stars: ✭ 230 (+576.47%)
Mutual labels:  socket
Socket.core
This is a socket framework based on C # net standard2.0 write, can be used for .NET Framework / dotnet core assembly, can run in window (IOCP) / linux (epoll) .Use asynchronous connection, asynchronous send, asynchronous receive, Performance burst tables, and pass the stress test. 这是一个基于C# .net standard2.0 写的socket框架,可使用于.net Framework/dotnet core程序集,能在window(IOCP)/linux(epoll)运行.使用异步连接,异步发送,异步接收,性能爆表,并且通过压力测试。
Stars: ✭ 203 (+497.06%)
Mutual labels:  socket
Unitysocketprotobuf3demo
主要实现了用Unity对接了Leaf服务器。其次带了些小工具。
Stars: ✭ 244 (+617.65%)
Mutual labels:  socket
Socks
Fully featured SOCKS proxy client supporting SOCKSv4, SOCKSv4a, and SOCKSv5. Includes Bind and Associate functionality.
Stars: ✭ 200 (+488.24%)
Mutual labels:  socket
Pypacker
📦 The fastest and simplest packet manipulation lib for Python
Stars: ✭ 216 (+535.29%)
Mutual labels:  socket
Chattt
❯❯❯ Chat without leaving your terminal
Stars: ✭ 239 (+602.94%)
Mutual labels:  socket
Systemjs Hot Reloader
reloads your modules as needed so that you can have satisfyingly fast feedback loop when developing your app
Stars: ✭ 215 (+532.35%)
Mutual labels:  socket

C++20 HTTP client

C++20 HTTP client is an HTTP/HTTPS client library written in C++20.

As of now, only GCC and MSVC support all of the C++20 features used in this library. Additionally, there are some C++20 features that are not used in the library because no compiler or standard library yet supports them. However the library will be updated over time as compilers start implementing more of C++20.

Aims and features

  • User friendly, functional design.
  • An API that is hard to misuse.
  • Library code follows C++ core guidelines.
  • A single module file when build systems and compilers have good support for modules. Until then, one source and one header file.
  • Safe and easy to use TCP Socket abstraction with support for TLS encryption.
  • HTTP requests, both unsecured and over TLS.
  • Asynchronous requests.
  • Callbacks for inspecting and/or cancelling responses while being received.
  • Support for Windows, Linux and MacOS.
  • Free from warnings with all useful warning flags turned on.
  • Modern CMake integration.
  • UTF-8 support.

Simple "GET" request example

Note that the fmt library is not a dependency of this library, it's just to simplify the example.

See the examples directory for more examples.

#include <cpp20_http_client.hpp>
#include <fmt/format.h>

int main() {
    try {
        auto const response = http_client::get("https://www.google.com")
            .add_header({.name="HeaderName", .value="header value"})
            .send();
        fmt::print("Date from server: {}.\n", response.get_header_value("date").value_or("Unknown"));
        http_client::utils::write_to_file(response.get_body(), "index.html");
    } 
    catch (http_client::errors::ConnectionFailed const& error) {
        fmt::print("The connection failed - \"{}\"\n", error.what());
    }
}

Dependencies

The only non-native dependency is OpenSSL on Linux and MacOS. It is recommended to use a package manager like VCPKG to install the OpenSSL libraries, especially on MacOS.

CMake usage

Building and installing

You can download, build and install the library as shown below. You only need to do this if you want to use the library as an installation.

git clone https://github.com/avocadoboi/cpp20-http-client.git
cd cpp20-http-client
mkdir build
cd build
cmake ..
cmake --build . --target cpp20_http_client --config Release
cmake --install .

You may want to add some flags to the cmake commands, for example the VCPKG toolchain file or a cmake prefix path for OpenSSL on Linux and MacOS. Use the latest GCC or MSVC compiler to build. You may need to add sudo to the install command, or run the command prompt as administrator on Windows.

If you are making changes to the code then use one of the toolchain files in the cmake directory to add warning flags. Do this by adding -DCMAKE_TOOLCHAIN_FILE=cmake/Msvc.cmake or -DCMAKE_TOOLCHAIN_FILE=cmake/GccClang.cmake to the CMake build generation command. These include the VCPKG toolchain file if a VCPKG_ROOT environment variable is available.

Using the installed library

To include the installed library in a CMake project, use find_package like so:

find_package(Cpp20HttpClient CONFIG REQUIRED)
target_link_libraries(target_name PRIVATE Cpp20HttpClient::cpp20_http_client)

Where target_name is the name of the target to link the library to.

Using the library as a subproject

You can clone the library into your own project and then use it like so:

add_subdirectory(external/cpp20-http-client)
target_link_libraries(target_name PRIVATE Cpp20HttpClient::cpp20_http_client)

Where target_name is the name of the target to link the library to. "external/cpp20-http-client" is just an example of where you could put the library in your project.

Using CMake to download and include the library

You can use the built-in FetchContent CMake module to directly fetch the repository at configure time and link to it:

include(FetchContent)

FetchContent_Declare(
    Cpp20HttpClient
    GIT_REPOSITORY https://github.com/avocadoboi/cpp20-http-client.git
)
FetchContent_MakeAvailable(Cpp20HttpClient)

target_link_libraries(target_name PRIVATE Cpp20HttpClient::cpp20_http_client)

Development status

All planned functionality has been implemented and tested. There are some improvements left that are possible and quite big things which may be seen as missing like response caching. These things can easily be extended to the library in the future if there's any need or demand for them. The library will also be updated as more C++20 features become available.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].