API for Zia Epitech 2021
If you have questions regarding the library, I would like to invite you to open an issue at GitHub. Please describe your request, problem, or question as detailed as possible. Opening an issue at GitHub allows other users and contributors to this library to collaborate. If you have a look at the closed issues, you will see that we react quite timely in most cases.
Only if your request would contain confidential information, please send us an email.
The documentation was generated with Doxygen. You can generate it yourself with :
cd docs && doxygen Doxyfile && firefox html/index.html
How to add ZiApi to your project :
git clone [email protected]:KillianG/ZiApi.git
It is necessary to compiles with C++17 flags.
set(CMAKE_CXX_STANDARD 17)
include_directories(ZiApi/API ZiApi/API/HTTP)
Expected behaviour :
Http namespace :
ZiApi namespace :
You can check the UML and the behaviour
Beside the examples below, you may want to check the documentation. All example files can be compiled and executed on their own.
Assume you want to create your Module object
class SSLModule : public ZiApi::Module {
public:
SSLModule(ZiApi::Core &core) {
_name = "SSL";
int priority = 0; //The module priority can be set in the config file
core.getModuleMgr()->addToPipeline(priority, _name); //Add the module to the processing list
};
const std::string &getName() const noexcept override { return _name; }
ModuleStatus handle(Http::Request &request, Http::Response &response) override {
/* It's up to you */
std::cout << __PRETTY_FUNCTION__ << std::endl; //virtual ZiApi::Module::ModuleStatus SSLModule::handle(Http::Request&, Http::Response&)
auto &header = response.getHeader();
header["Host"] = std::string("127.0.0.1:4242"); //Sets the response's header
response.setHttpVersion(1, 1); //Sets the response's http version
response.setStatusMessage("OK"); //Sets the response's status message
response.setStatusCode(Http::Response::StatusCode::OK); //Sets the response's status code
response.setBody("<html><body><h1>Title</h1></body></html>"); //Sets the response's body
return ModuleStatus::OK;
}
};
extern "C" {
std::unique_ptr<ZiApi::Module> createModule(ZiApi::Core &core) { //It will be called by the dl functions
return std::make_unique<SSLModule>(core); //Gives the Core to the module if needed
}
}
The createModule(ZiApi::Core &core)
function must be defined. It is the entry point of your module
- CMake for build automation
- Doxygen to generate documentation
- RFC 2616
- Cppreference
The class is licensed under the MIT License:
Copyright © 2019 Killian Gardahaut
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.