All Projects → includeos → mana

includeos / mana

Licence: other
IncludeOS C++ Web Application Framework

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects
python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to mana

conan-sdl2
[OBSOLETE] The recipe is now in https://github.com/bincrafters/community
Stars: ✭ 13 (-80.88%)
Mutual labels:  conan
conan-openssl
[OBSOLETE] The recipe is now in https://github.com/conan-io/conan-center-index
Stars: ✭ 25 (-63.24%)
Mutual labels:  conan
nexus-repository-conan
Conan the Barbarian, C packaging, fun times
Stars: ✭ 37 (-45.59%)
Mutual labels:  conan
conan-ffmpeg
[OBSOLETE] The recipe is now in https://github.com/bincrafters/community
Stars: ✭ 32 (-52.94%)
Mutual labels:  conan
conan-grpc
[OBSOLETE] The recipe is now in https://github.com/conan-io/conan-center-index - Conan remote archive: https://bincrafters.jfrog.io/artifactory/api/conan/conan-legacy-inexorgame
Stars: ✭ 33 (-51.47%)
Mutual labels:  conan
palladio
Palladio enables the execution of CityEngine CGA rules inside of SideFX Houdini.
Stars: ✭ 92 (+35.29%)
Mutual labels:  conan
docs
conan.io reStructuredText documentation
Stars: ✭ 93 (+36.76%)
Mutual labels:  conan
conan-sfml
[OBSOLETE] The recipe is now in https://github.com/bincrafters/community
Stars: ✭ 13 (-80.88%)
Mutual labels:  conan
tribe
Conan 2.0 Tribe
Stars: ✭ 43 (-36.76%)
Mutual labels:  conan
chucknorris
Source code for the "Let's Build Chuck Norris!" project
Stars: ✭ 23 (-66.18%)
Mutual labels:  conan
wishlist
This repo is to propose libraries, frameworks, and code in general that users would like to have in conan
Stars: ✭ 49 (-27.94%)
Mutual labels:  conan
Spatial.Engine
[WIP] Spatial is a cross-platform C++ game engine.
Stars: ✭ 50 (-26.47%)
Mutual labels:  conan
conan-qt
[OBSOLETE] The recipe is now in https://github.com/conan-io/conan-center-index
Stars: ✭ 72 (+5.88%)
Mutual labels:  conan
templates
Collection of Conan recipe + CI templates
Stars: ✭ 71 (+4.41%)
Mutual labels:  conan
cmake-init
The missing CMake project initializer
Stars: ✭ 1,071 (+1475%)
Mutual labels:  conan
Conan
Conan - The open-source C/C++ package manager
Stars: ✭ 5,498 (+7985.29%)
Mutual labels:  conan
conan-gtest
[OBSOLETE] The recipe is now in https://github.com/conan-io/conan-center-index
Stars: ✭ 11 (-83.82%)
Mutual labels:  conan

mana

IncludeOS C++ Web Application Framework

Acorn is a web server built with Mana which demonstrates a lot of its potential.

Some insight in the implementation of mana can be found in this post.

Usage

It's easy to get started - check out the examples.

using namespace mana;
using namespace std::string_literals;

std::unique_ptr<Server> server;

void Service::start(const std::string&)
{
  Router router;

  // GET /
  router.on_get("/", [](auto, auto res) {
    res->add_body("<html><body><h1>Simple example</h1></body></html>"s);
    res->send();
  });

  server = std::make_unique<Server>(net::Inet4::stack());
  server->set_routes(router).listen(80);
}

Routes

Routes is where the server end-points are defined.

Router router;

// GET /
router.on_get("/", [] (auto req, auto res) {
  // Serve index.html
});

// POST /users
router.on_post("/users", [] (auto req, auto res) {
  // Register new user
});

server.set_routes(router);

There is also support for named parameters in routes.

// GET /users/:id
router.on_get("/users/:id(\\d+)", [](auto req, auto res) {
  auto id = req->params().get("id");
  // Do actions according to "id"
  if(id == "42")
    // ...
});

Middleware

Middleware are tasks which are executed before the user code defined in routes.

// Declare a new middleware
class MyMiddleware : public mana::Middleware {
  // ...
};

// Add a middleware object
Middleware_ptr my_mw = std::make_shared<MyMiddleware>();
server.use(my_mw);

It's also possible to just add a simple task with a lambda.

// Add a middleware lambda
server.use([] (auto req, auto res) {
  // My custom middleware function
  (*next)(); // Don't forget to call next if no response was sent!
});

Psst, there is already some ready-made middleware for Mana!

Attributes

Attributes is a way to extend the Request object with additional data.

// Declare a new attribute
class MyAttribute : public Attribute {
  // ...
};

// Set attribute in middleware
MyMiddleware::process(auto req, auto res, auto next) {
  auto attr = std::make_shared<MyAttribute>();
  req->set_attribute(attr);
  (*next)();
}

// Use attribute in route
router.use("/my-route", [] (auto req, auto res) {
  if(auto attr = req->get_attribute<MyAttribute>()) {
    // Do things with "attr"
  }
});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].