Seastar
High performance C++ framework for concurrent servers
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
json_path.hh
1/*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18/*
19 * Copyright 2015 Cloudius Systems
20 */
21
22#pragma once
23
24#ifndef SEASTAR_MODULE
25#include <vector>
26#endif
27
28#include <seastar/http/common.hh>
29#include <seastar/core/sstring.hh>
30#include <seastar/http/routes.hh>
31#include <seastar/http/function_handlers.hh>
32#include <seastar/util/modules.hh>
33
34namespace seastar {
35
36namespace httpd {
37
43SEASTAR_MODULE_EXPORT
49 : method(GET) {
50 }
51
57 json_operation(operation_type method, const sstring& nickname)
58 : method(method), nickname(nickname) {
59 }
60
61 operation_type method;
62 sstring nickname;
63
64};
65
81SEASTAR_MODULE_EXPORT
83 //
84 enum class url_component_type {
85 PARAM, // a normal path parameter (starts with / and end with / or end of path)
86 PARAM_UNTIL_END_OF_PATH, // a parameter that contains all the path entil its end
87 FIXED_STRING, // a fixed string inside the path, must be a full match and does not count
88 // as a parameter
89 };
90
91 // path_part is either a parameter or a fixed string
92 struct path_part {
93 sstring name;
94 url_component_type type = url_component_type::PARAM;
95 };
96
100 path_description() = default;
101
111 path_description(const sstring& path, operation_type method,
112 const sstring& nickname,
113 const std::vector<std::pair<sstring, bool>>& path_parameters,
114 const std::vector<sstring>& mandatory_params);
115
125 path_description(const sstring& path, operation_type method,
126 const sstring& nickname,
127 const std::initializer_list<path_part>& path_parameters,
128 const std::vector<sstring>& mandatory_params);
129
146 path_description* pushparam(const sstring& param,
147 bool all_path = false) {
148 params.push_back( { param, (all_path) ? url_component_type::PARAM_UNTIL_END_OF_PATH : url_component_type::PARAM});
149 return this;
150 }
151
162 params.push_back( { url, url_component_type::FIXED_STRING});
163 return this;
164 }
171 path_description* pushmandatory_param(const sstring& param) {
172 mandatory_queryparams.push_back(param);
173 return this;
174 }
175
176 std::vector<path_part> params;
177 sstring path;
178 json_operation operations;
179 mutable routes::rule_cookie _cookie;
180
181 std::vector<sstring> mandatory_queryparams;
182
183 void set(routes& _routes, handler_base* handler) const;
184
185 void set(routes& _routes, const json_request_function& f) const;
186
187 void set(routes& _routes, const future_json_function& f) const;
188
189 void unset(routes& _routes) const;
190};
191
192}
193
194}
Definition: handlers.hh:42
Definition: routes.hh:81
Definition: routes.hh:43
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
Definition: json_path.hh:44
json_operation(operation_type method, const sstring &nickname)
Definition: json_path.hh:57
json_operation()
Definition: json_path.hh:48
Definition: json_path.hh:82
path_description(const sstring &path, operation_type method, const sstring &nickname, const std::initializer_list< path_part > &path_parameters, const std::vector< sstring > &mandatory_params)
path_description * push_static_path_part(const sstring &url)
adds a fixed string as part of the path This will allow to combine fixed string URL parts and path pa...
Definition: json_path.hh:161
path_description(const sstring &path, operation_type method, const sstring &nickname, const std::vector< std::pair< sstring, bool > > &path_parameters, const std::vector< sstring > &mandatory_params)
path_description * pushmandatory_param(const sstring &param)
Definition: json_path.hh:171
path_description * pushparam(const sstring &param, bool all_path=false)
Definition: json_path.hh:146