Skip to content

Sunburst7/WebREST

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

$$WebREST$$

brief introduction

Enhanced version of tiny-muduo for personal learing purposes feature:

  • Using muduo mode(muti-thread + IO multiplexing + one loop per thread) to deal with Concurrency
  • Using C++11 thread API instead of pthread, somewhere using string-view
  • Support Post method, parse body data
  • Concisely create path handler, Supported methods(Put Delete Post Get) according to RESTful specifications
  • Automatically close useless long-connection
  • Simple usage, Simple import

reference:

Webbench stress test:

测试1

build

assuming you are in WebREST source directory, type in below:

mkdir build
cd build
# Release Version, Debug Version: change "Release" to "Debug"
cmake .. -DCMAKE_BUILD_TYPE=Release
make

then, everything is in /build

  • bin: executable file of example program
  • WebREST: essential file to import WebREST
    • include: all .h file
    • lib: static library file and shared library file

use

Refer to the complete project: https://github.com/Sunburst7/WebREST_example

in you own project, you can create a directory called "third" in the root directory. and then, you copy whole /build/WebREST into the /third directory. I give a example of http-server

#include <iostream>

#include "eventloop.h"
#include "inet_address.h"
#include "http.h"
#include "http_request.h"
#include "http_response.h"

using namespace std;
using namespace WebREST;

int main()
{
    EventLoop loop;
    InetAddress listen_addr(54321);
    HttpServer server(&loop, listen_addr, false);

    server.Get("/test", [](const HttpRequest& req, HttpResponse& resp){
        printf("/test handler\n");
        resp.set_status_code(HttpResponse::k200OK);
        resp.set_status_message("OK");
        resp.set_body("test hello!\n");
    });
    
    server.start();
    loop.loop();
}

now you project structure like this:

.
├── CMakeLists.txt
├── http_test.cc
└── third
    └── WebREST

in CMakeLists.txt, you can write this to import WebREST:

cmake_minimum_required(VERSION 3.15)
project(WebREST-test C CXX)
add_definitions(-std=c++17)

include_directories(${PROJECT_SOURCE_DIR}/third/WebREST/include)

add_executable(http_test http_test.cc)

target_link_libraries(http_test ${PROJECT_SOURCE_DIR}/third/WebREST/lib/libWebREST-static.a -lpthread)

Ok, you are ready for Compiling, type under code in terminal:

# in root directory
mkdir build && cd build
cmake ..
make

About

enhanced version for tiny-muduo

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages