๐๐ป C++์ httplib๋ฅผ ์ฌ์ฉํ ๋งค์ฐ ๊ฐ๋จํ ์น์๋ฒ ์
๋๋ค.
This is a very simple web server using C++’s httplib.
๐๐ป ์ฌ์ฉ๋ฐฉ๋ฒ์ nodejs express์๋ฒ์ ๋งค์ฐ ์ ์ฌํฉ๋๋ค.
The usage is very similar to the Node.js Express server.
๐๐ป์ฝ๋ / Code
โ๏ธ httplib.h
— ์๋์ ๋ช
๋ น์ด๋ก ๋ค์ด๋ก๋ํฉ๋๋ค.
Download using the command below.
curl -L https://raw.githubusercontent.com/yhirose/cpp-httplib/master/httplib.h -o httplib.h
โ๏ธ httplib_server.cpp
#include "httplib.h"
#include <iostream>
int main()
{
httplib::Server svr;
svr.Get("/",[](const httplib::Request &req, httplib::Response &res){
res.set_content("Hello from cpp-httplib!","text/plain");
});
svr.Get("/hi", [](const httplib::Request &req, httplib::Response &res) {
res.set_content("Hi! from cpp-httplib!", "text/plain");
});
std::cout << "cpp-httplib server listening on http://localhost:8080" << std::endl;
svr.listen("0.0.0.0", 8080);
return 0;
}
๐๐ป ์ปดํ์ผ / Compiling
g++ -o httplib_server httplib_server.cpp -std=c++11 -pthread
๐๐ป์คํ / run
โ๏ธ ์๋ฒ ์คํ / Run server
./httplib_server
โ๏ธ ๋ธ๋ผ์ฐ์ ์์ ์๋ฒ ์ ์ / Connect to server from browser

