This API uses both composition and inheritance to provide a generic way to set up a custom server with a custom communication protocol and custom middlewares.
You can for instance put an HTTP server as well as an FTP or SMTP one. Here is a small overview of how a pipeline works:
-
Setup phase
- The
PipelineManagercontains an instance of theListener,PacketParser,ReplySenderand a vector of allModulesused by the pipeline. - The
PipelineManagerwill send it'sprocessRequestmethod as a callback to theonPacketmethod of the listener - When the
listenmethod of theListeneris called, theListenerstarts listen for new packets.
- The
-
Processing phase
- When the
Listenerreceives a full packet, it just calls corresponding callback (theprocessRequestmethod from thePipelineManager) - The
PipelineManagerwill then call thePacketParser, giving it the raw request. ThePacketParserwill return the parsed request. - The
PipelineManagerwill next call eachModulein the order they have been registered with the parsed request and a blank response. The modules will then mutate the request and/or the response. - When all modules are called, the
PipelineManagerwill call the reply sender to send back the reply to the client.
- When the
Pipeline request workflow:
note that the only differences between http and https pipeline are the listener (the HTTPS one will decrypt SSL) and the
sender (the http one will encrypt using SSL) as the pipeline is extremely modular
There are two ways to install the API.
- create a
cmake/folder at the root of your project - copy the FindZiapi.cmake and paste it in the cmake folder.
- add
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")in the root CMakeLists.txt - add
find_package(ziapi)in the root CMakeLists.txt - Use
target_link_libraries()with the target and theziapitarget to link the headers with all targets that will need it
With this procedure, CMake will automatically clone the repository in your cmake build folder and update it everytime there is an update on the API.
cmake:
add_subdirectory(ziapi)
find_package(ziapi)
add_executable(
zia
src/main.cpp
)
target_link_libraries(
zia
ziapi
# Add other libs here
)- Clone the repository in your project
- Use
add_subdirectory()in your CMakeLists.txt with, as parameter the path to the cloned folder. - Use
target_link_libraries()with the target and theziapitarget to link the headers with all targets that will need it.
shell:
git clone https://github.com/aurelien-boch/ziapicmake:
add_subdirectory(ziapi)
add_executable(
zia
src/main.cpp
)
target_link_libraries(
zia
ziapi
# Add other libs here
)