a web server that will print hello world on the screen only for linux users
Note: This lib is currently under development you can check the source code and even use it but dn't use it for production purpose
git clone https://github.com/notadevps/socket.git
cd socket
./run.sh
sudo ./install.sh
use SOCKET in command line
main.cpp file
#include <iostream>
#include <socket.h>
#include <config.h>
int main()
{
Socket si;
Socket::App app;
std::pair<std::string, void(*)(Socket::Req&, Socket::Res&)> a;
a.first = "/";
a.second = [](Socket::Req& req, Socket::Res& res)
{
req.method = std::string{ "GET" };
res.content_type = Socket::Content_Type::TEXT_HTML;
res.status_code = 200;
res.content = "hello world!";
};
std::pair<std::string, void(*)(Socket::Req&, Socket::Res&)> b;
b.first = "/goggle";
b.second = [](Socket::Req & req, Socket::Res& res)
{
req.method = std::string{ "GET" };
res.content_type = Socket::Content_Type::TEXT_HTML;
res.status_code = 200;
res.content = "hello google";
};
std::pair<std::string, void(*)(Socket::Req&, Socket::Res&)> c;
c.first = "/foo";
c.second = [](Socket::Req & req, Socket::Res& res)
{
req.method = std::string{ "GET" };
res.content_type = Socket::Content_Type::TEXT_HTML;
res.status_code = 200;
res.content = "boo";
};
app.push_back(a);
app.push_back(b);
app.push_back(c);
si.app(&app);
si.init(3000);
return 0;
}
- localhost:3000/foo -> will print boo
- localhost:3000/google -> will print hello google
- localhost:3000/ -> will print hello world
- adding threads
- adding more content_type and header opt
- optimization