Skip to content
This repository has been archived by the owner on Oct 29, 2022. It is now read-only.

A simple C++ backend framework -- A course lab for Computer Networks at ZJU.

Notifications You must be signed in to change notification settings

CHN-ChenYi/HTTPSimple-Net2021

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTPSimple-Net2021

A simple C++ backend framework -- A course lab for Computer Networks at ZJU.

Features

  • Decouple the network framework and controllers
  • Use a network lib based on edge-triggered epoll, task queue and thread pool to provide high-concurrency, high-performance network IO
  • Support asynchronous controllers to avoid blocking the main thread

Hello World Example

#include "HTTPSimple.hpp"

void hello_world_controller(
    const HttpRequestPtr&&,
    std::function<void(const HttpResponsePtr&,
                       const HttpStatusCode& status_code)>&& callback) {
  HttpResponsePtr resp = std::make_unique<HttpResponse>();
  resp->SetContentType("text/html");
  const std::string s("Hello World!");
  resp->SetBody(std::move(s), s.size());
  callback(resp, HttpStatusCode::OK);
};

int main() {
  Server server;
  server.RegisterController(HttpMethod::GET, "/hello", hello_world_controller)
      .Listen(8080);

  return 0;
}

For more examples, please refer to the example folder and main.cc.

Compile and Run

Requires C++17.

cmake -B ./build -DCMAKE_BUILD_TYPE=Release .
make -C ./build -j
./build/HTTPSimple

About

A simple C++ backend framework -- A course lab for Computer Networks at ZJU.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published