NetFlex  0.0.0
C++11 HTTP Server Library.
route.hpp
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2015-2017 Simon Ninon <simon.ninon@gmail.com>
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #pragma once
24 
25 #include <functional>
26 #include <string>
27 
28 #include <netflex/http/method.hpp>
29 #include <netflex/http/request.hpp>
30 #include <netflex/http/response.hpp>
31 #include <netflex/routing/route_matcher.hpp>
32 
33 namespace netflex {
34 
35 namespace routing {
36 
42 class route {
43 public:
48  typedef std::function<void(const http::request&, http::response&)> route_callback_t;
49 
50 public:
58  route(http::method m, const std::string& path, const route_callback_t& callback);
59 
61  ~route(void) = default;
62 
64  route(const route&) = default;
66  route& operator=(const route&) = default;
67 
68 public:
74  bool match(http::request& request) const;
75 
76 public:
83  void dispatch(const http::request& request, http::response& response) const;
84 
85 private:
89  http::method m_method;
90 
94  std::string m_path;
95 
99  route_callback_t m_callback;
100 
104  route_matcher m_matcher;
105 };
106 
107 } // namespace routing
108 
109 } // namespace netflex
route(http::method m, const std::string &path, const route_callback_t &callback)
route & operator=(const route &)=default
assignment operator
std::function< void(const http::request &, http::response &)> route_callback_t
Definition: route.hpp:48
void dispatch(const http::request &request, http::response &response) const
bool match(http::request &request) const
Definition: route.hpp:42
Definition: client.hpp:33
Definition: route_matcher.hpp:39
~route(void)=default
default dtor
Definition: response.hpp:37
Definition: request.hpp:39