crackme0107 / wfrest

C++ Web Framework REST API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

中文版入口

✨ wfrest: C++ Web Framework REST API

Fast🚀, efficient⌛️, and easiest💥 c++ async micro web framework based on C++ Workflow.

C++ Workflow is a light-weighted C++ Parallel Computing and Asynchronous Networking Engine.

If you need performance and good productivity, you will love ✨wfrest✨.

Contents

Dicssussion

For more information, you can first see discussions:

https://github.com/wfrest/wfrest/discussions

Build

Requirement

  • Linux , like ubuntu 18.04 or newer
  • Cmake
  • zlib1g-dev
  • libssl-dev
  • libgtest-dev
  • gcc and g++ or llvm + clang, tested with ubuntu 20.04

If you are on ubuntu 20.04, you may install them by command:

apt-get install build-essential cmake zlib1g-dev libssl-dev libgtest-dev -y

For more details, you can see here : requirement details

Shell

sudo ./build.sh

For test

./test.sh

Cmake

git clone https://github.com/wfrest/wfrest
cd wfrest
mkdir build && cd build
cmake .. 
sudo make -j  
sudo make install

Docker

Use dockerfile, the Dockerfile locate /docker subdirectory of root source code repository.

docker build -t wfrest ./docker/ubuntu/

If you are using podman, you can also build it. and tested under ubuntu 20.04

podman build -t wfrest ./docker/ubuntu/

Or you can Pull from DockerHub

docker pull wfrest/wfrest

Quick start

#include "wfrest/HttpServer.h"
using namespace wfrest;

int main()
{
    HttpServer svr;

    // curl -v http://ip:port/hello
    svr.GET("/hello", [](const HttpReq *req, HttpResp *resp)
    {
        resp->String("world\n");
    });
    // curl -v http://ip:port/data
    svr.GET("/data", [](const HttpReq *req, HttpResp *resp)
    {
        std::string str = "Hello world";
        resp->String(std::move(str));
    });

    // curl -v http://ip:port/post -d 'post hello world'
    svr.POST("/post", [](const HttpReq *req, HttpResp *resp)
    {
        // reference, no copy here
        std::string& body = req->body();
        fprintf(stderr, "post data : %s\n", body.c_str());
    });

    if (svr.start(8888) == 0)
    {
        getchar();
        svr.stop();
    } else
    {
        fprintf(stderr, "Cannot start server");
        exit(1);
    }
    return 0;
}

About

C++ Web Framework REST API

License:Apache License 2.0


Languages

Language:C++ 97.8%Language:CMake 1.2%Language:C 0.9%Language:Dockerfile 0.1%Language:Shell 0.0%Language:Python 0.0%Language:Lua 0.0%