Add hello world server example
parent
98aeeae012
commit
ec753c14c3
@ -0,0 +1,28 @@
|
||||
#include "webcc/response_builder.h"
|
||||
#include "webcc/server.h"
|
||||
|
||||
class HelloView : public webcc::View {
|
||||
public:
|
||||
webcc::ResponsePtr Handle(webcc::RequestPtr request) override {
|
||||
if (request->method() == "GET") {
|
||||
return webcc::ResponseBuilder{}.OK().Body("Hello, World!")();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
try {
|
||||
webcc::Server server(8080);
|
||||
|
||||
server.Route("/", std::make_shared<HelloView>());
|
||||
|
||||
server.Run();
|
||||
|
||||
} catch (const std::exception&) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
#include "webcc/view.h"
|
||||
|
||||
namespace webcc {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
//ResponsePtr DetailView::Handle(RequestPtr request, const UrlArgs& args) {
|
||||
// if (request->method() == methods::kGet) {
|
||||
// return Get(args, UrlQuery(request->url().query()));
|
||||
// }
|
||||
//
|
||||
// if (request->method() == methods::kPut) {
|
||||
// return Put(request, args);
|
||||
// }
|
||||
//
|
||||
// if (request->method() == methods::kPatch) {
|
||||
// return Patch(request, args);
|
||||
// }
|
||||
//
|
||||
// if (request->method() == methods::kDelete) {
|
||||
// return Delete(args);
|
||||
// }
|
||||
//
|
||||
// return ResponsePtr();
|
||||
//}
|
||||
//
|
||||
//ResponsePtr DetailView::Get(const UrlArgs& args, const UrlQuery& query) {
|
||||
// return ResponsePtr();
|
||||
//}
|
||||
//
|
||||
//ResponsePtr DetailView::Put(RequestPtr request, const UrlArgs& args) {
|
||||
// return ResponsePtr();
|
||||
//}
|
||||
//
|
||||
//ResponsePtr DetailView::Patch(RequestPtr request, const UrlArgs& args) {
|
||||
// return ResponsePtr();
|
||||
//}
|
||||
//
|
||||
//ResponsePtr DetailView::Delete(const UrlArgs& args) {
|
||||
// return ResponsePtr();
|
||||
//}
|
||||
|
||||
} // namespace webcc
|
Loading…
Reference in New Issue