Coder Social home page Coder Social logo

arpit2297 / luna Goto Github PK

View Code? Open in Web Editor NEW

This project forked from degoodmanwilson/luna

0.0 2.0 0.0 6.84 MB

Yet another web framework—this time in modern C++!

Home Page: https://luna.goodman-wilson.com

License: MIT License

Shell 0.34% CMake 2.59% Python 2.15% C++ 94.37% C 0.16% CSS 0.03% HTML 0.05% JavaScript 0.02% Ruby 0.29%

luna's Introduction

Build Status Coverage Status badge

Luna

Full Documentation

A web application and API framework in modern C++

A web application and API framework in modern C++, Luna is designed to be easy to use and integrate with any C++ project that needs to serve HTTP endpoints. Luna’s core philosophy is that it should be easy to use correctly and difficult to use incorrectly. Of course, it should be robust as well.

You are writing in C++ (because C++ is awesome), and your app needs to provide a lightweight HTTP server to communicate with other web services. libmicrohttpd is super-awesome, except for that idiomatically C API. Luna is an idiomatically C++ wrapper for libmicrohttpd that leans on modern C++ programming concepts.

HTTP server creation, start, shut down, and deletion are all handled behind the scenes with the magic of RAII. Starting a server is automatic with instantiating a server object, and allowing your server object to fall out of scope is all that is needed to cleanly shut it down. There is nothing else for you to keep track of, or allocate.

Adding endpoints to your server is likewise meant to be simple. Nominate an endpoint with a string or regex and an HTTP verb, and pass in a lambda or other std::functional-compatible object (function pointers, bound class member functions), and return a string containing the desired response body. Of course, you can set headers and mime types, too.

Example code

But don't take my word for it. Here is some code for serving a simple JSON snippet from a single endpoint.

#include <string>
#include <luna/luna.h>

using namespace luna;

int main(void)
{
    //start a server delivering JSON by default on the default port 8080
    server server;

    // Handle GET requests to "localhost:8080/endpoint"
    // Respond with a tiny bit of fun JSON
    auto router = server.create_router("/");

    router->set_mime_type("application/json"); //the default is "text/html; charset=UTF-8"

    router->handle_request(request_method::GET, "/endpoint",
                          [](auto request) -> response
    {
        return {"{\"made_it\": true}"};
    });

    server.start(); //run forever, basically, or until the server decides to kill itself.
}

Prerequisites

A C++14 capable compiler (tested against gcc 4.9, clang 3.6), CMake 2.8. Conan for installing dependencies.

License

MIT

luna's People

Contributors

degoodmanwilson avatar jsrois avatar

Watchers

James Cloos avatar Arpit Hamirwasia  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.