Giter Site home page Giter Site logo

crud's Introduction

CRUD

High performance Restful web-service library written in C++11 based on boost.ASIO and CRUD handlers

This library supports persistent connections to achieve highest throughput and utilizes optinally regex for enpoints

build

Installing from GitHub

git clone https://github.com/venediktov/CRUD.git

Building on Linux

$ mkdir Release
$ cd Release
$ cmake -DCMAKE_BUILD_TYPE=Release -DCRUD_WITH_EXAMPLES=1 .. -G "Unix Makefiles"
$ make -j $(nproc) install

Building on Mac OS

$ mkdir Release
$ cd Release
$ cmake -DCMAKE_BUILD_TYPE=Release -DCRUD_WITH_EXAMPLES=1 .. -G "Unix Makefiles"
$ make -j $(sysctl -n hw.physicalcpu) install

Running examples

$ cd Release/examples
$ ./webserver 0.0.0.0 8080 . & 
$ ./simple_restful_service 0.0.0.0 8081 . & 
$ ./regex_restful_service 0.0.0.0 8082 . & 
$ ./persisted_regex_restful_service 0.0.0.0 8083 . &

Testing output and benchmarks

curl localhost:8080
curl localhost:8081/venue_handler/RTB
curl localhost:8082/venue_handler/ANY/123
curl localhost:8083/venue_handler/ANY/123
ab -k -n 100000 -c 30 http://localhost:8081/RTB
ab -k -n 100000 -c 30 http://localhost:8082/ANY/123
ab -k -n 100000 -c 30 http://localhost:8083/ANY/123

Stop all background examples

pkill -9 "persisted|restful|webserver"

Utilizing API

REST handler with regex

    using regex_restful_dispatcher_t =  http::crud::crud_dispatcher<http::server::request, http::server::reply>;
    regex_restful_dispatcher_t regex_handler(".") ; //root is irrelavant for REST only used for web-server
    regex_handler.crud_match(boost::regex("/venue_handler/(\w+)") )
                 .post([](http::server::reply & r, const http::crud::crud_match<boost::cmatch> & match) {
                    r << "{}" << http::server::reply::flush("json") ;
                    std::cout << "POST group_1_match=[ << match[1] << "], request_data=" << match.data << std::endl;
                 });

simple REST handler

   // SIMPLE NO REGEX MATCH FOR POST "/venue_handler/RTB"
    using simple_restful_dispatcher_t = http::crud::crud_dispatcher<http::server::request, http::server::reply, std::string, std::string>;
    simple_restful_dispatcher_t simple_handler(".") ; //root is irrelavant for REST only used for web-server
    simple_handler.crud_match(std::string("/venue_handler/RTB") )
                  .post([](http::server::reply & r, const http::crud::crud_match<std::string> & match) {
                     r << "{}" << http::server::reply::flush("json") ;
                     std::cout << "POST request_data=" << match.data << std::endl;
                   });

All in one go

    // CREAT/READ/UPDATE/DELETE "/venue_handler/XEMDP/123"
    handler.crud_match(boost::regex("/venue_handler/(\\w+)/(\\d+)") )
           .put([](http::server::reply & r, const http::crud::crud_match<boost::cmatch> & match)
              std::cout << "CREATE request=" << match[0] << "/" << match[1] << std::endl;
              r = http::server::reply::stock_reply(http::server::reply::no_content);
           })
           .get([](http::server::reply & r, const http::crud::crud_match<boost::cmatch> & match) {
              r << "name: " << match[1] << ", instance number: " << match[2]
                << http::server::reply::flush("text") ;
              std::cout << "READ request=" << match[0] << std::endl;
           })
           .post([](http::server::reply & r, const http::crud::crud_match<boost::cmatch>  & match) {
              r << "name: " << match[1] << ", instance number: " << match[2]
                << http::server::reply::flush("text") ;
              std::cout << "UPDATE request=" << match[0] << std::endl;
              std::cout << "UPDATE request_data=" << match.data << std::endl;
           })
           .del([](http::server::reply & r, const http::crud::crud_match<boost::cmatch> & match)
              std::cout << "DELETE request=" << match[0] << "/" << match[1] << std::endl;
              r = http::server::reply::stock_reply(http::server::reply::no_content);
           }) ;

Setting up connection types

For keep-alive persistent connections specifiy second template argument with presistent type for connection

http::server::server<simple_restful_dispatcher_t, http::server::persistent_connection> server{host,port,handler};

By default server is using non-persistent connection from the library

http::server::server<simple_restful_dispatcher_t> server{host,port,handler};

Adding CRUD as GitHub submodule to your project

Create a file .gitmodules in the root of your project with contents

[submodule "CRUD"]
	path = CRUD
	url = https://github.com/venediktov/CRUD.git

Or execute following command in your repo

git submodule add https://github.com/venediktov/CRUD

If you add CRUD as submodule you will have to use git clone --recursive for your repo in order to get us as dependency

You can look at GitHub subtrees instead git subtree add --prefix CRUD [email protected]:venediktov/CRUD.git master --squash

Support on Beerpay

Hey dude! Help me out for a couple of 🍻!

Beerpay Beerpay

crud's People

Contributors

abushev avatar donhinton avatar venediktov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

crud's Issues

Cannot compile in Ubuntu 18.04

I'm getting the following error:
/CRUD/service/mime_types.hpp:60:65: error: ‘constexpr const char* http::server::mime_types::extension_to_type(const char*)’ called in a constant expression
constexpr const char* GIF = mime_types::extension_to_type("gif");

enable Travis CI

  • review travis.yml file if it does not work then fix it
  • add build to Travis CI
  • add build shield.io to README.md

examples folder

  • add examples folder
  • move main.cpp to examples forlder
  • add few examples
  • conditional compilation of examples folder in cmake
  • wiki how to sync a fork to CRUD repo

Support for Windows

If it works add to README how to build this library on Windows

  • Visual Studio 2015
  • Visual Studio 2017

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.