Add hello world server example

This commit is contained in:
Chunting Gu
2019-07-04 12:23:41 +08:00
parent 98aeeae012
commit ec753c14c3
6 changed files with 70 additions and 54 deletions
+32
View File
@@ -104,6 +104,38 @@ You can then parse `r->data()` to JSON object with your favorite JSON library. M
## Server API Examples
### Hello, World!
```cpp
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;
}
```
### Book Store
Suppose you want to create a book server and provide the following operations with RESTful API:
- Query books based on some criterias.