8000 GitHub - XLTools/lattice: C++11 HTTP Library
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jul 17, 2021. It is now read-only.

XLTools/lattice

 
 

Repository files navigation

lattice

Lattice is a C++11, cross-platform HTTP library, inspired by Python's Requests and C++ Requests.

Table of Contents

Motivation

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.

Features

  • 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

Design

Lattice has four main components: adapters, connections, requests and responses.

  1. Adapters wrap native sockets or SSL connections into an interface with 4 core methods: open, close, write, and read.
  2. Connections wrap specific adapters, and add shared methods like DNS lookup.
  3. Requests format data for HTTP requests, with user-friendly methods like setAuth or setMultiPart.
  4. Responses parse data sent from the server.

Dependencies

  • C++11 Compiler
  • CMake
  • Native threads (POSIX or Win32)
  • (Optional) OpenSSL

SSL/TLS support is header-only, the library itself has no SSL dependencies.

Building

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

Portability

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

Documentation

Coming soon, for now, see the the examples for how to use lattice.

Planned Features

  • OAuth
  • Asynchronous requests

Contributors

  • Alex Huszagh

Lattice is a fork of C++ Requests with a different backend, and credits those contributors in authors.

Contributor Guidelines

All useful pull requests will be merged, provided that they do not add external dependencies and follow these guidelines.

  1. Preprocessor macros should be used sparingly.
  2. Code syntax should not depend on the preprocessor.
  3. Your code must be readable.

License

MIT, see license.

About

C++11 HTTP Library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 98.0%
  • CMake 1.7%
  • JavaScript 0.3%
0