feat: add example

This commit is contained in:
dancingCycle 2023-01-23 14:32:26 +01:00
parent 674e2dbca3
commit 489d2bb344
2 changed files with 35 additions and 0 deletions

15
example/main.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <httpserver.hpp>
using namespace httpserver;
class hello_world_resource : public http_resource {
public:
std::shared_ptr<http_response> render(const http_request&) {
return std::shared_ptr<http_response>(new string_response("Hello, World!"));
}
};
int main(int argc, char** argv) {
webserver ws = create_webserver(8080);
hello_world_resource hwr;
ws.register_resource("/hello", &hwr);
ws.start(true);
return 0;
}

20
example/makefile Normal file
View File

@ -0,0 +1,20 @@
#target: dependency_1 dependency_2 dependency_3 ...
# command
#
RM = /bin/rm -f
OBJ = main.o
EXE = main
CC = /usr/bin/g++
CXXFLAGS = -Wall
LDFLAGS = -L/usr/local/lib -lhttpserver
#
all: $(EXE)
#
$(EXE): $(OBJ)
$(CC) $(CXXFLAGS) $(LDFLAGS) $(OBJ) -o $(EXE)
#
main.o: main.cpp
$(CC) -c main.cpp -o main.o
#
clean:
$(RM) $(OBJ) $(EXE) *~