Need help with ehttp?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

hongliuliao
283 Stars 95 Forks Apache License 2.0 281 Commits 0 Opened issues

Description

simple http server base on epoll

Services available

!
?

Need anything else?

Contributors list

# 175,040
Shell
C
c-plus-...
javaee
143 commits
# 57,558
Shell
C
c-plus-...
android...
2 commits

ehttp

C/C++ CI Build Status codecov.io

This library make http (with json) microservice easy!

Feature

  • Base on linux epoll
  • Multi-thread model

Performance (without log print)

  • Connect per request: qps 12000+ (ab -c 10 -n 10000 localhost:3456/hello)
  • Connection keep alive: qps 18000+ (ab -c 10 -n 10000 -k localhost:3456/hello)

Build && Test

 make && make test && ./output/test/hello_server 3456
 curl "localhost:3456/hello"

Function List

  • http 1.0/1.1(keep-alive support) GET/POST request
  • response as json format

Example

#include 
#include 
#include "simple_log.h"
#include "http_server.h"

// Make sure the callback method is threadsafe void login(Request &request, Json::Value &root) { std::string name = request.get_param("name"); std::string pwd = request.get_param("pwd");

LOG_DEBUG("login user which name:%s, pwd:%s", name.c_str(), pwd.c_str());

root["code"] = 0;
root["msg"] = "login success!";

}

int main() { HttpServer http_server;

http_server.add_mapping("/login", login, POST_METHOD);

http_server.set_port(3456);
http_server.start_sync();
return 0;

}

Run

[email protected]:~/workspace/ehttp$ curl -d "name=tom&pwd=3" "localhost:3456/login"
{"code":0,"msg":"login success!"}

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.