An open API service indexing awesome lists of open source software.

https://github.com/arsdever/expresscpp

Express server written in C++
https://github.com/arsdever/expresscpp

Last synced: 3 months ago
JSON representation

Express server written in C++

Awesome Lists containing this project

README

          

# ExpressC++

This is a library similar to ExpressJS framework. It was developed for
`C++`/`Qt` developers to make it easier to develop web applications.

# Usage

## Preparations

First of all you have to have installed [Qt 5.12.2](http://download.qt.io/official_releases/qt/5.12/5.12.2/)*

(*note that the application was developed under Qt v5.12.2, that's why the reference is to this version. It may work with the newer versions as well*)

After that download and build the project. It will require extra sources (general [interfaces](https://github.com/opensalad/interfaces) provided by [opensalad organization](https://github.com/opensalad)).
```
cd ~
git clone https://github.com/opensalad/interfaces
git clone https://github.com/arsdever/expresscpp
cd expresscpp
qmake
make
```

*__If case you download components in different folders, please have a look at the `.pro` file of `expresscpp` component to make sure that given include path is correct__*

## Example code

This is a simple code that uses the library.

``` c++
// example.cpp
#include
#include

using namespace ad::http;

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

Server express;
express.GET(QRegularExpression("/*"), [](Server::request_t &req, Server::response_t &res) {
res.setBody("Hello World");
});
express.begin();

return app.exec();
}
```

## Example `.pro` file

``` makefile
TEMPLATE = app
TARGET = application
DEFINES += QT_DEPRECATED_WARNINGS
LIBS += -L../expresscpp -lexpresscpp
INCLUDEPATH +=
SOURCES += example.cpp
QT += core
```

### Result

After all preparings, build the application using the following command from `example` containing directory
``` bash
qmake
make
```
and run it (don't miss to update `LD_LIBRARY_PATH` or simply copy the `expresscpp.so.*` files into directory)
``` bash
LD_LIBRARY_PATH= ./application
```
or
``` bash
cp /*.so* ./
./application
```
or add post-build event into `expresscpp.pro` file to copy built libraries into this path.

Now open any application to make a `HTTP GET call`. Enter uri `localhost:8008/any/path`. Do call and you will get respond
> Hello World

# Contribution

If you would like to contribute, please feel free for any feedback, code contribution, feature offer, code advice and etc. Also feel free to create an issue.

# 3rd party

As you can guess, the library is based on `Qt` library. In future it's planned to remove all `Qt` dependencies.