Lattice is a C++11, cross-platform HTTP library, inspired by Python's Requests and C++ Requests.
Table of Contents
- Motivation
- Features
- Design
- Dependencies
- Building
- Portability
- Documentation
- Planned Features
- Contributors
- Contributor Guidelines
- Credits
- License
Lattice is a modern, thread-safe, HTTP library for C++11. No more hand-encoded URL parameters or international domain names. No more manual authentication.
1. Code
#include <lattice.hpp>
#include <iostream>
int main(int argc, char *argv[])
{
lattice::Url url = {"http://httpbin.org/basic-auth/user/pass"};
lattice::Authentication auth = {"user", "pass"};
auto response = lattice::Get(url, auth);
std::cout << response.body() << std::endl;
}
2. Build & Run
$ g++ get.cpp -o get -std=c++11 liblattice.a
$ ./get
{
"authenticated": true,
"user": "user"
}
Compare this to the same code using cURL. No external libraries, no defines, no unresolved symbols. No hassle.
- Custom Headers
- Parameters
- Cookies
- DNS caching
- Redirections
- Content-Type detection
- Pooled requests
- International domain names
- Unicode Support (UTF8, UTF16, UTF32)
- Auth (Basic, Digest)
- Proxies (Beta)
HTTPS Only
- SSL/TLS Adapters
- Domain validation
- Certificate validation
Lattice has four main components: adapters, connections, requests and responses.
- Adapters wrap native sockets or SSL connections into an interface with 4 core methods:
open
,close
,write
, andread
. - Connections wrap specific adapters, and add shared methods like DNS lookup.
- Requests format data for HTTP requests, with user-friendly methods like
setAuth
orsetMultiPart
. - Responses parse data sent from the server.
- C++11 Compiler
- CMake
- Native threads (POSIX or Win32)
- (Optional) OpenSSL
SSL/TLS support is header-only, the library itself has no SSL dependencies.
Simply clone, configure with CMake, and build.
git clone https://github.com/Alexhuszagh/lattice.git
cd lattice/build
cmake .. -DBUILD_EXAMPLES=ON # "-DWITH_OPENSSL=ON" for SSL examples
make -j 5 # "msbuild lattice.sln" for MSVC
Lattice has been tested with the following compilers and operating systems:
- 64-bit Linux with Clang 3.8.2
- 64-bit Linux with GCC 5.4.0
- 32/64-bit Windows with MinGW 5.3.0 (MXE, MinGW, and MSYS2)
- 32/64-bit Windows with Visual Studio 14 2015
Coming soon, for now, see the the examples for how to use lattice.
- OAuth
- Asynchronous requests
- Alex Huszagh
Lattice is a fork of C++ Requests with a different backend, and credits those contributors in authors.
All useful pull requests will be merged, provided that they do not add external dependencies and follow these guidelines.
- Preprocessor macros should be used sparingly.
- Code syntax should not depend on the preprocessor.
- Your code must be readable.
MIT, see license.