-
Notifications
You must be signed in to change notification settings - Fork 1.1k
How to set up the HTTP server
kytooooo edited this page Aug 29, 2020
·
7 revisions
Using HTTP and coroutine to support the sync feature, even though it's a sync function, it doesn't block the main thread!
Base on Libevent, you need to add a callback function when using the async HTTP feature.
To setup Http service you must call the code below:
NFIHttpModule* m_pHttpNetModule = pPluginManager->FindModule<NFIHttpServerModule>();
//http://127.0.0.1/json
m_pHttpNetModule->AddRequestHandler("/json", NFHttpType::NF_HTTP_REQ_GET, this, &NFHelloWorld::OnCommandQuery);
m_pHttpNetModule->AddRequestHandler("/json", NFHttpType::NF_HTTP_REQ_POST, this, &NFHelloWorld::OnCommandQuery);
m_pHttpNetModule->AddRequestHandler("/json", NFHttpType::NF_HTTP_REQ_DELETE, this, &NFHelloWorld::OnCommandQuery);
m_pHttpNetModule->AddRequestHandler("/json", NFHttpType::NF_HTTP_REQ_PUT, this, &NFHelloWorld::OnCommandQuery);
m_pHttpNetModule->AddNetFilter("/json", this, &NFHelloWorld::OnFilter);
m_pHttpNetModule->InitServer(8080);
To know more details, please debug the project Tutorial5.