2012-09-27 18:05:36 -07:00
|
|
|
cpp-httplib
|
|
|
|
===========
|
2012-09-21 19:38:33 -07:00
|
|
|
|
2012-10-05 10:58:56 -07:00
|
|
|
A C++11 header-only HTTP library.
|
2012-09-22 21:41:21 -07:00
|
|
|
|
|
|
|
[The Boost Software License 1.0](http://www.boost.org/LICENSE_1_0.txt)
|
2012-09-25 19:21:42 -07:00
|
|
|
|
2012-10-05 10:58:56 -07:00
|
|
|
It's extremely easy to setup. Just include **httplib.h** file in your code!
|
|
|
|
|
2012-09-27 18:05:36 -07:00
|
|
|
Server Example
|
|
|
|
--------------
|
2012-09-25 19:21:42 -07:00
|
|
|
|
2012-10-12 13:09:39 -07:00
|
|
|
Inspired by [Sinatra](http://www.sinatrarb.com/) and [express](https://github.com/visionmedia/express).
|
2012-09-27 18:05:36 -07:00
|
|
|
|
|
|
|
#include <httplib.h>
|
2012-09-25 19:21:42 -07:00
|
|
|
|
2012-09-27 18:05:36 -07:00
|
|
|
int main(void)
|
|
|
|
{
|
2012-10-05 10:58:56 -07:00
|
|
|
using namespace httplib;
|
|
|
|
|
2012-10-12 13:09:39 -07:00
|
|
|
Server svr;
|
2012-09-27 18:05:36 -07:00
|
|
|
|
2014-03-31 18:07:56 -07:00
|
|
|
svr.get("/hi", [](const auto& req, auto& res) {
|
2012-10-12 13:09:39 -07:00
|
|
|
res.set_content("Hello World!", "text/plain");
|
2012-09-27 18:05:36 -07:00
|
|
|
});
|
|
|
|
|
2012-10-12 13:09:39 -07:00
|
|
|
svr.listen("localhost", 1234);
|
2012-09-25 19:21:42 -07:00
|
|
|
}
|
|
|
|
|
2012-10-03 22:18:18 -07:00
|
|
|
Client Example
|
|
|
|
--------------
|
|
|
|
|
|
|
|
#include <httplib.h>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2012-10-05 10:58:56 -07:00
|
|
|
httplib::Client cli("localhost", 1234);
|
2012-10-03 22:18:18 -07:00
|
|
|
|
|
|
|
auto res = cli.get("/hi");
|
|
|
|
if (res && res->status == 200) {
|
|
|
|
std::cout << res->body << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-31 18:07:56 -07:00
|
|
|
Copyright (c) 2014 Yuji Hirose. All rights reserved.
|