mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 01:08:27 +00:00
Added httpsvrkit.h and sample.
This commit is contained in:
parent
c568deaba1
commit
dfe95a669d
3 changed files with 330 additions and 0 deletions
17
example/Makefile
Normal file
17
example/Makefile
Normal file
|
@ -0,0 +1,17 @@
|
|||
|
||||
USE_CLANG = 1
|
||||
|
||||
ifdef USE_CLANG
|
||||
CC = clang++
|
||||
CFLAGS = -std=c++0x -stdlib=libc++
|
||||
else
|
||||
CC = g++
|
||||
CFLAGS = -std=c++11
|
||||
endif
|
||||
|
||||
sample : sample.cc ../httpsvrkit.h
|
||||
$(CC) -o sample $(CFLAGS) -I.. sample.cc
|
||||
|
||||
.PHONY : test
|
||||
test: sample
|
||||
./sample
|
36
example/sample.cc
Normal file
36
example/sample.cc
Normal file
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
// sample.cc
|
||||
//
|
||||
// Copyright (c) 2012 Yuji Hirose. All rights reserved.
|
||||
// The Boost Software License 1.0
|
||||
//
|
||||
|
||||
#include <httpsvrkit.h>
|
||||
#include <cstdio>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
using namespace httpsvrkit;
|
||||
|
||||
Server svr;
|
||||
|
||||
svr.post("/", [](const Request& /*req*/, Response& res) {
|
||||
res.body_ = "<html><head></head><body><ul></ul></body></html>";
|
||||
});
|
||||
|
||||
svr.post("/item", [](const Request& req, Response& res) {
|
||||
res.body_ = req.pattern_;
|
||||
});
|
||||
|
||||
svr.get("/item/:name", [](const Request& req, Response& res) {
|
||||
try {
|
||||
res.body_ = req.params_.at("name");
|
||||
} catch (...) {
|
||||
// Error...
|
||||
}
|
||||
});
|
||||
|
||||
svr.run("0.0.0.0", 1234);
|
||||
}
|
||||
|
||||
// vim: et ts=4 sw=4 cin cino={1s ff=unix
|
Loading…
Add table
Add a link
Reference in a new issue