Framework for native web applications in C++, focused on simplicity.
NAWA is a framework for web applications written in C++(17). It aims to
make writing native web apps nearly as easy as writing them
in specialized scripting languages (such as PHP). It provides the
necessary features, such as sessions, request filters (for providing
static elements such as images), and accessing and controlling all
aspects of requests and responses (GET, POST, cookies, …). Scroll on
for a list of features.
NAWA communicates with the web server via FastCGI and currently uses
the fastcgi++ lite library for efficient request handling.
It also comes
with an integrated development web server (HTTP Request Handler) which can
serve your application without depending on dedicated web server software
(still somehow experimental and unfit for production use).
New in v0.9
Sessions can now be used without cookies by manually passing the session ID when starting
the session. A new overload of nawa::Session::start()
has been added for this purpose.
New in v0.8
The configuration can now be reloaded without restarting and apps (and request handling
functions) can be hot-swapped. This allows you to update your app without interrupting
request handling. Reloading can be done via systemd or by sending a SIGHUP signal to
nawarun. If you are using NAWA as a library, take a look at
nawa::RequestHandler::reconfigure()
.
Almost all data members of classes have become methods, therefore, it is necessary to
update existing apps before upgrading. Please note that the project has been extensively
restructured, therefore it might also be necessary to correct the includes of existing apps.
Additionally, this release adds support for macOS.
The following example is the complete C++ source code of a NAWA app that
answers every request with the “Hello World!”. It’s that simple.
#include <nawa/application.h>
using namespace nawa;
int init(AppInit &appInit) {
return 0;
}
int handleRequest(Connection &connection) {
connection.responseStream() << "Hello World!";
return 0;
}
You want to learn more?
Read the full introduction tutorial.
If you don’t like the IoC-style approach, you can also use NAWA as a library.
An introduction can be found here.
This project is still in an early state (version 0.9!). It might, of
course, still contain bugs. Use it at your own risk.
If you use it, please report any bugs and wishes, so that this project
might reach a higher version number at some point 😃
Also, the ABI and API can still change at any time, making
modifications to your apps (or, at least, recompilation) necessary. When such
changes happen, the version number will be increased, and nawarun will refuse to
load apps compiled against an older version.
A NAWA app consists of:
You can find an introduction containing a simple “Hello World!”
NAWA app here:
Getting started.
The path to the object file is included in the config file, and NAWA
will take care of setting everything up and starting the app. You
can run it like this:
nawarun /path/to/config.ini
(or just nawarun
if the file is named
config.ini
and located in the current working directory).
Run nawarun -h
or nawarun --help
for information on command line
options (config overrides, starting without config file).
If systemd is present on your system, a systemd service file will
also be installed on your system. You can start an app as a
daemon using the path to its ini file (/path/to/config.ini):
sudo systemctl start [email protected]
For automatically starting an app on boot, use systemctl enable
.
NAWA has been tested especially on Linux, but also runs fine
on macOS (both as a library and using nawarun) (1). It will
probably also run on other BSD derivates, but this has not
been tested.
Windows is not supported and never will be.
Please note: All commands in the following instructions should be
run as an unprivileged user. Commands which must run as root are
prepended with sudo
.
(1) Please note that due to a bug in Apple Clang, building will only Compiling with Apple Clang works fine
succeed with gcc, which can be installed using homebrew. Other dependencies
may also be installed using homebrew.
on macOS 12, dependencies still have to be installed from homebrew.
For running NAWA apps via nawarun / applications using libnawa:
For building (additionally):
For building the docs, doxygen must be installed. However, you can also
access the docs online.
To build nawarun, pull the source code, open a terminal, and
switch to the NAWA directory. If you haven’t pulled the source code
yet, do it:
git clone https://github.com/jatofg/nawa.git nawa
cd nawa
First, create a directory for the build files:
mkdir build
cd build
Create the build configuration:
cmake -DCMAKE_BUILD_TYPE=RELEASE ..
Note: You can pass some arguments to cmake to influence the build configuration:
-DBuildTests=ON
-DBuildSharedLib=ON
-DBuildStaticLib=ON
-DBuildNawarun=OFF
-DBuildExamples=OFF
-DBuildDocs=OFF
(disabled automatically if doxygen is not installed)-DEnableArgon2=OFF
Build NAWA (nawarun and the shared library, tests, examples, and docs, depending on your
cmake arguments):
make
And last, install it to the target directories so that the apps
can find it (this will also install the headers needed for app development):
sudo make install
In the build directory, run:
sudo xargs rm < install_manifest.txt
Uninstalling before installing a new version is recommended to avoid ancient
relics remaining on your system.
Binary packages are not available yet, just build it yourself 😃
This project includes the following libraries (in the libs directory)
with different (less strict) licenses:
libs/base64/LICENSE
for detailslibs/inih/LICENSE.txt
for detailslibs/libbcrypt/COPYING
for detailslibs/punycode/LICENSE
for detailsIt automatically downloads the following libraries during build configuration: