All Projects → ef-gy → Cxxhttp

ef-gy / Cxxhttp

Licence: mit
Asynchronous, Header-only C++ HTTP-over-(TCP|UNIX Socket|STDIO) Library

Programming Languages

cpp
1120 projects

Projects that are alternatives of or similar to Cxxhttp

Firefly
Firefly is an asynchronous web framework for rapid development of high-performance web application.
Stars: ✭ 277 (+1054.17%)
Mutual labels:  asynchronous, http-client, http-server
Foxy
Session-based Beast/Asio wrapper requiring C++14
Stars: ✭ 57 (+137.5%)
Mutual labels:  http-client, asio, http-server
Lithium
Easy to use C++17 HTTP Server with no compromise on performances. https://matt-42.github.io/lithium
Stars: ✭ 523 (+2079.17%)
Mutual labels:  asynchronous, http-client, http-server
Qtnetworkng
QtNetwork Next Generation. A coroutine based network framework for Qt/C++, with more simpler API than boost::asio.
Stars: ✭ 125 (+420.83%)
Mutual labels:  http-client, asio, http-server
Beast
HTTP and WebSocket built on Boost.Asio in C++11
Stars: ✭ 3,241 (+13404.17%)
Mutual labels:  http-client, asio, http-server
foxy
Session-based Beast/Asio wrapper requiring C++14
Stars: ✭ 61 (+154.17%)
Mutual labels:  http-client, asio, http-server
Dubbogo
a golang micro-service framework compatible with alibaba dubbo
Stars: ✭ 258 (+975%)
Mutual labels:  http-client, http-server
Armeria
Your go-to microservice framework for any situation, from the creator of Netty et al. You can build any type of microservice leveraging your favorite technologies, including gRPC, Thrift, Kotlin, Retrofit, Reactive Streams, Spring Boot and Dropwizard.
Stars: ✭ 3,392 (+14033.33%)
Mutual labels:  http-client, http-server
Netty Http Client
An asynchronous http client in Java, with a clean, callback-based API, using Netty 4.x
Stars: ✭ 295 (+1129.17%)
Mutual labels:  asynchronous, http-client
Comet
Modern PHP framework for building blazing fast REST APIs, CRUDs and microservices
Stars: ✭ 328 (+1266.67%)
Mutual labels:  http-client, http-server
EthernetWebServer
This is simple yet complete WebServer library for AVR, Portenta_H7, Teensy, SAM DUE, SAMD21/SAMD51, nRF52, STM32, RP2040-based, etc. boards running Ethernet shields. The functions are similar and compatible to ESP8266/ESP32 WebServer libraries to make life much easier to port sketches from ESP8266/ESP32. Coexisting now with `ESP32 WebServer` and…
Stars: ✭ 118 (+391.67%)
Mutual labels:  http-client, http-server
Jetty.project
Eclipse Jetty® - Web Container & Clients - supports HTTP/2, HTTP/1.1, HTTP/1.0, websocket, servlets, and more
Stars: ✭ 3,260 (+13483.33%)
Mutual labels:  http-client, http-server
Restc Cpp
Modern C++ REST Client library
Stars: ✭ 371 (+1445.83%)
Mutual labels:  http-client, asio
Atom
Java course materials
Stars: ✭ 293 (+1120.83%)
Mutual labels:  http-client, http-server
httoop
HTTOOP - a fully object oriented HTTP protocol library written in python
Stars: ✭ 15 (-37.5%)
Mutual labels:  http-client, http-server
Libuv
Cross-platform asynchronous I/O
Stars: ✭ 18,615 (+77462.5%)
Mutual labels:  asynchronous, unix
Apfree wifidog
A hight performance and lightweight captive portal solution for HTTP(s)
Stars: ✭ 519 (+2062.5%)
Mutual labels:  http-client, http-server
Ocaml Cohttp
An OCaml library for HTTP clients and servers using Lwt or Async
Stars: ✭ 533 (+2120.83%)
Mutual labels:  http-client, unix
Restinio
Cross-platform, efficient, customizable, and robust asynchronous HTTP/WebSocket server C++14 library with the right balance between performance and ease of use
Stars: ✭ 694 (+2791.67%)
Mutual labels:  asio, http-server
asio-grpc
Asynchronous gRPC with Asio/unified executors
Stars: ✭ 100 (+316.67%)
Mutual labels:  asynchronous, asio

CXXHTTP

A C++ library implementing an asynchronous HTTP server and client.

To clone this library, make sure you also clone the submodules. The --recursive flag should do this for you:

git clone --recursive https://github.com/ef-gy/cxxhttp.git

Features

This library implements HTTP/1.1 for clients as well as servers. It's fairly minimalistic, yet there's a few nifty parts that wouldn't strictly have been necessary.

Some of these are:

  • HTTP Content Negotation
  • HTTP over TCP, UNIX sockets and STDIO
  • CLI help screen with servlet summaries
  • Optional OPTIONS implementation, with a markdown body that shows the supported methods and the relevant location regex
  • Optional TRACE implementation
  • Basic 100-continue flow
  • Basic request validation
  • Fallback HEAD handler

I believe the STDIO feature is quite unique, as is the excellent test coverage of the library, for both the client and the server code.

Non-Features

Some features didn't make it into the library for various reasons - mostly to keep it small. Some of these are:

  • HTTP 'chunked' Transfer Encoding - or any non-identity encoding, really
  • HTTP Date headers, or any other timekeeping-related code
  • Query string parsing - use REST API style location strings instead
  • Logging - though there are internal flags and counters, which e.g. the Prometheus client library based on this makes use of
  • Any form of SSL/TLS support - use a frontend server to provide this for you

Some of the omissions technically make this non-conforming to the HTTP/1.1 standard, but seeing as how the primary purpose of this library is to sit behind an nginx (or similar) HTTP web server, this shouldn't be an issue in practice.

Compiler Requirements

You must have a GNU make and a C++ compiler that supports C++14. On most modern-ish Linux distributions that's pretty easy: just update your PMS and install clang++ or g++. Preferrably clang++. No reason.

OSX

On OSX, you'll be fine if you just install a current version of XCode.

Ubuntu (LTS)

On Ubuntu, you're in for a bit of a rough ride. The only reliable way I've found of getting things to compile, at least on 14.04, is to install this PPA and use g++ 4.9:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-4.9

To compile things, add CXX=g++-4.9 to your make commands, like this:

make test CXX=g++-4.9

This may not be necessary if you haven't installed clang++ and if there's no other versions of g++ installed. clang++ doesn't work on Ubuntu in c++14 mode, because libc++ hasn't been updated past an ancient SVN snapshot.

Debian/Raspbian

On Debian and Raspbian it should be sufficient to just update your package sources and install clang++ and libc++:

apt-get update
apt-get install clang++ libc++1 libc++-dev

Test suite

The library has a test suite, which you can run like this:

make test

If this fails, something is wrong. Please open an issue at GitHub with the log: https://github.com/ef-gy/cxxhttp/issues

Getting Started

This library uses the ASIO asynchronous I/O headers as well as libefgy. If you are starting a new project, it's probably easiest to use the build headers from libefgy and git submodules to pull in the dependencies.

The following set of commands ought to get you started:

PROJECT=funtastic-example
git init ${PROJECT}
cd ${PROJECT}
git submodule add https://github.com/ef-gy/libefgy.git dependencies/libefgy
git submodule add https://github.com/chriskohlhoff/asio.git dependencies/asio
git submodule add https://github.com/ef-gy/cxxhttp.git dependencies/cxxhttp
mkdir include
mkdir include/${PROJECT}
mkdir src
ln -s ../dependencies/asio/asio/include/asio include/asio
ln -s ../dependencies/asio/asio/include/asio.hpp include/asio.hpp
ln -s ../dependencies/cxxhttp/include/cxxhttp include/cxxhttp
ln -s ../dependencies/libefgy/include/ef.gy include/ef.gy

A trivial makefile to get you started would look like this:

-include ef.gy/base.mk include/ef.gy/base.mk
NAME:=funtastic-example

A very trivial sample server would be this (see src/server.cpp):

#define ASIO_DISABLE_THREADS
#include <cxxhttp/httpd.h>
using namespace cxxhttp;

static void hello(http::sessionData &session, std::smatch &) {
  session.reply(200, "Hello World!");
}

static http::servlet servlet("/", ::hello);

int main(int argc, char *argv[]) { return cxxhttp::main(argc, argv); }

If you saved this as src/example.cpp, then you could run it like this:

make example
./example http:localhost:8080

This will run the server and to see what it does, use:

curl -i http://localhost:8080/

Which should print the "Hello World!" from above.

You can run the ./example programme without arguments to see all the available command line options. In particular, there is "http:unix:...", which lets you run your server on a UNIX socket.

See src/server.cpp for additional commentary, and the include/cxxhttp/httpd-....h headers, which implement additional common features that web servers tend to have.

I'm lazy, can I clone this example from somewhere?

Sure, try this:

git clone --recursive https://github.com/ef-gy/cxxhttp-example.git

Note the --recursive - that's because this is using submodules.

Usage

You really should be running this behind a real web servers, for security and such. Look into nginx for that, which is really good at forward-proxying.

Updating to a newer version of the libraries

The command you're looking for is built into git:

git submodule update --recursive --remote

Don't forget to commit the new state of the dependencies/ directory, if any of the libraries had updates.

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].