Code Monkey home page Code Monkey logo

pico's Introduction

PICO

Overview

Pico is a C++17/20 based HTTP web application framework running on Linux/macOS/Unix

Its main features are as follows:

  • Use a non-blocking I/O network lib based on libevent to provide high-concurrency, high-performance network IO;
  • Support Http1.0/1.1 (server side and client side);
  • Support https (based on OpenSSL);
  • Support WebSocket (server side and client side);
  • Support JSON format request and response, very friendly to the Restful API application development;
  • Support filter chains to facilitate the execution of unified logic (such as login verification, etc.) before or after handling HTTP requests;
  • Support file download;
  • Support Redis with reading and writing;
  • Support MongoDB with reading and writing;
  • Support reload configuration file at load time;
  • Support Http2 (server side and client side);
  • Support GRPC (server side and client side);
  • Support TLS(thread local storage) mechanism;

Quick Example

Below is the main program of a typical pico application:

#include "gamelibs/app.hpp"

USE_NAMESPACE_FRAMEWORK

int main(int argc, char** argv)
{
    CheckCondition(CApp::Start(argc, argv), EXIT_FAILURE);
    return EXIT_SUCCESS;
}

void CApp::WebRegister(CHTTPServer* srv) {
    srv->Register(
        "/game/v1/logevent",
        ghttp::HttpMethod::POST,
        [](ghttp::CRequest* req, ghttp::CResponse* rsp) {
            if (req->GetBody().empty())
                return rsp->Response({ ghttp::HttpStatusCode::BADREQUEST, "Invalid Parameters" });
            try {
                auto j = nlohmann::json::parse(req->GetBody());
                const auto& name = j["name"].get<std::string>();
                const auto& parm = j["parm"].get<std::string>();
                CClickHouseMgr::Instance().Push(name, parm);
            } catch (const std::exception& e) {
                SPDLOG_ERROR("CTX:{} /game/v1/logevent exception {}", MYARGS.CTXID, e.what());
                return rsp->Response({ ghttp::HttpStatusCode::INTERNAL, e.what() });
            }

            nlohmann::json js;
            return rsp->Response({ ghttp::HttpStatusCode::OK, js.dump() });
        });
}

Install Pico

Install dependency libraries

cd external
sh install.sh

Build

cmake -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_PREFIX_PATH="/data/user00/pico/serverdev/src/external" -H. -Bbuild
cd build && make -j4

Launch

./bin/PICO -f ../config/config.yaml

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.