Skip to content
forked from azadkuh/qhttp

a light-weight and asynchronous HTTP library (both server & client) in Qt5 and c++14

License

Notifications You must be signed in to change notification settings

CLAY-BIOS/qhttp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QHttp

Table of contents

About

TOC

QHttp is a lightweight, asynchronous and fast HTTP library in c++14 / Qt5, containing both server and client side classes for managing connections, parsing and building HTTP requests and responses.

  • the objective of QHttp is being light weight with a simple API for Qt developers to implement RESTful web services in private (internal) zones. more
  • by using std::function and c++14 generic lambda, the API is intentionally similar to the Node.js' http module. Asynchronous and non-blocking HTTP programming is quite easy with QHttp. have a look at sample codes.
  • the fantastic nodejs/http-parser (which is a single pair of *.h/*.c files) is the only dependency of the QHttp.

attention: c++14 is the minimum requirement for version 3.0+ please see releases

This project was inspired by nikhilm/qhttpserver effort to implement a Qt HTTP server. QHttp pushes the idea further by implementing client side classes, better memory management, a lot more Node.js-like API, ...

Sample codes

TOC

a HelloWorld HTTP server by QHttp looks like:

int main(int argc, char** argv) {
    QCoreApplication app(argc, argv);

    using namespace qhttp::server;
    QHttpServer server(&app);
    server.listen( // listening on 0.0.0.0:8080
        QHostAddress::Any, 8080,
        [](QHttpRequest* req, QHttpResponse* res) {
            // http status 200
            res->setStatusCode(qhttp::ESTATUS_OK);
            // the response body data
            res->end("Hello World!\n");
            // automatic memory management for req/res
    });

    if ( !server.isListening() ) {
        qDebug(