You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.0 KiB
C++
45 lines
1.0 KiB
C++
#ifndef WEBCC_REST_SERVER_H_
|
|
#define WEBCC_REST_SERVER_H_
|
|
|
|
// HTTP server handling REST requests.
|
|
|
|
#include <string>
|
|
|
|
#include "webcc/http_server.h"
|
|
#include "webcc/rest_request_handler.h"
|
|
#include "webcc/rest_service.h"
|
|
|
|
namespace webcc {
|
|
|
|
class RestServer : public HttpServer {
|
|
public:
|
|
RestServer(std::uint16_t port, std::size_t workers)
|
|
: HttpServer(port, workers) {
|
|
}
|
|
|
|
~RestServer() override = default;
|
|
|
|
// Bind a REST service to the given URL path.
|
|
// The URL should start with "/" and it will be treated as a regular
|
|
// expression if |is_regex| is true.
|
|
// Examples:
|
|
// - "/instances"
|
|
// - "/instances/(\\d+)"
|
|
// Binding to the same URL multiple times is allowed, but only the last one
|
|
// takes effect.
|
|
bool Bind(RestServicePtr service, const std::string& url, bool is_regex) {
|
|
return request_handler_.Bind(service, url, is_regex);
|
|
}
|
|
|
|
private:
|
|
HttpRequestHandler* GetRequestHandler() final {
|
|
return &request_handler_;
|
|
}
|
|
|
|
RestRequestHandler request_handler_;
|
|
};
|
|
|
|
} // namespace webcc
|
|
|
|
#endif // WEBCC_REST_SERVER_H_
|