download and install Qt 5.6 or later from qt.io

Building from source

$ git clone git://git.qt-users.jp/codereview/qthttpserver.git
$ mkdir build
$ cd $_
$ qt5/bin/qmake
$ make
$ (sudo) make install
$ ./examples/hello/httphelloserver

open localhost:8080

Build from source

$ git clone git://git.qt-users.jp/codereview/qtwebservice.git
$ cd qtwebservice
$ qt5/bin/qmake
$ make
$ (sudo) make install
$ ./examples/webservice/official/official
qtwebservice is running on 8080

open localhost:8080

helloworld.pro

TEMPLATE = app
TARGET = helloworld
QT = webservice
SOURCES += main.cpp
RESOURCES += main.qrc

main.cpp

#include <QtCore/QCoreApplication>
#include <QtWebService/QWebServiceEngine>

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

    QWebServiceEngine engine(QStringLiteral(":/config.qml"));
    engine.start();

    return app.exec();
}

main.qrc

<RCC>
    <qresource prefix="/">
        <file>config.qml</file>
        <file>root/index.qml</file>
    </qresource>
</RCC>

config.qml

import QtWebService.Config 0.1

Config {
    listen.address: '*'
    listen.port: 8080
    server.name: 'QtWebService'

    contents: {
        '/': './root/',
    }

    cache: {
        'qml': true
    }

    deflate: {
        'video/*': false
        , 'image/*': false
    }
}

root/index.qml

import QtWebService.HTML 5.0

Html {
    Head { title: 'QtWebService' }
    Body {
        H1 { text: 'QtWebService' }
        P { text: '...' }
    }
}

Build & Run

$ qmake && make -j4 && ./helloworld

Default configuration

import QtWebService.Config 0.1

Config {
    listen: Listen {
        address: '*'
        port: 8080
    }

    server.name: 'QtWebService'

    contents: {}

    daemons: []

    imports: []

    cache: {}

    deflate: {}
}

listen.address

"*"
listen any address
"localhost"
listen localhost only
"nnn.nnn.nnn.nnn"
listen an ip address

listen.port

port number

contents

path -> document root pair

daemons

background services

offlineStoragePath

root path for offline storage

imports

additional import path for QML

cache

if false, qtwebservice generates html from qml everytime

deflate

mime types not to be compressed