Setting up cpp-httplib with Cmake For Building REST API
Setting up cpp-httplib with Cmake For Building REST API
In this blog I'll be using cpp-http lib, a header only ( single file ) c++ server & client.
I'll be using it with Cmake to run an http server.
Here is the link to the project on github. Click here
I'll start by creating a directory for the project.
Next I'll create the Files I need :
Creating the build directory
CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(api)
add_executable(api main.cpp)
target_include_directories(
api
PRIVATE
${cmake_current_dir}
)
main.cpp
#include "httplib.h"
int main(void)
{
using namespace httplib;
Server svr;
svr.Get("/", [](const Request& req, Response& res) {
res.set_content("Hello World!", "text/plain");
});
svr.listen("localhost", 8080);
}
Build Steps :