GithubHelp home page GithubHelp logo

easyhttp's Introduction

A modern C++ http framework

easyhttp是采用C++开发的,使用方便的http server库。

License

Tutorial

  • Simple server

    #include "easyhttp/easyhttp.h"
    
    using namespace std::placeholders;
    using namespace easyhttp;
    
    void add(const std::shared_ptr<request>& req, const std::shared_ptr<response>& res)
    {
        int a = std::atoi(req->get_param_value("a").c_str());
        int b = std::atoi(req->get_param_value("b").c_str());
        res->set_response(std::to_string(a + b));
    }
    
    int main()
    {
        // 1.创建http server服务对象
        // 服务端将采用1个io线程和2个work线程服务
        auto server = std::make_shared<http_server>("0.0.0.0:6666", 1, 2);
    
        // 2.设置路由
        server->route("/add", std::bind(add, _1, _2));
    
        // 3.启动事件循环(非阻塞)
        server->run();
    
        std::cin.get();
        return 0;
    }

    在浏览器中输入该网址即可访问。

    http://localhost:6666/add?a=1&b=1
    

开发平台

  • Ubuntu17.10 gcc7.2.0

依赖性

  • boost
  • c++11

DONE

  • HTTP1.0。

TODO

  • HTTP1.1的支持。

License

This software is licensed under the MIT license. © 2018 chxuan

easyhttp's People

Contributors

chxuan avatar

Stargazers

 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

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.