41 template <
typename TController>
54 auto controller = app->GetServices()->GetRequiredService<TController>();
55 controller->Initialize(context);
59 static int HexCharToDecimal(
char c) {
60 if (c >=
'0' && c <=
'9')
return c -
'0';
61 if (c >=
'a' && c <=
'f')
return c -
'a' + 10;
62 if (c >=
'A' && c <=
'F')
return c -
'A' + 10;
66 static char DecodeHexByte(
char h1,
char h2) {
67 return static_cast<char>((HexCharToDecimal(h1) << 4) | HexCharToDecimal(h2));
74 while (pStr && pStr[i] !=
'\0') {
75 if (pStr[i] ==
'%' && pStr[i + 1] !=
'\0' && pStr[i + 2] !=
'\0') {
76 decoded += DecodeHexByte(pStr[i + 1], pStr[i + 2]);
78 }
else if (pStr[i] ==
'+') {
89 int openBrace = subPath.
IndexOf(
"{");
90 int closeBrace = subPath.
IndexOf(
"}");
91 if (openBrace >= 0 && closeBrace > openBrace + 1) {
94 if (ctx->GetRequest()->GetRouteValues().TryGetValue(paramName, val) && !val.
IsEmpty()) {
95 return UrlDecode(val);
97 if (ctx->GetRequest()->GetQuery().TryGetValue(paramName, val) && !val.
IsEmpty()) {
98 return UrlDecode(val);
106 if (ctx->GetRequest()->GetRouteValues().TryGetValue(
"id", val) && !val.
IsEmpty()) {
107 return UrlDecode(val);
110 if (!pathVal.
IsEmpty())
return pathVal;
111 if (ctx->GetRequest()->GetQuery().TryGetValue(
"id", val) && !val.
IsEmpty()) {
112 return UrlDecode(val);
114 auto queryKeys = ctx->GetRequest()->GetQuery().GetKeys();
115 if (queryKeys.GetLength() > 0 && ctx->GetRequest()->GetQuery().TryGetValue(queryKeys[0], val)) {
116 return UrlDecode(val);
123 : m_routePrefix(prefix) {}
132 auto controller = ResolveController(app, ctx);
133 return (controller.Get()->*action)();
139 template <
typename TResult,
typename = std::enable_if_t<!std::is_same_v<TResult, DotNetDupe::System::String>>>
142 auto controller = ResolveController(app, ctx);
143 auto result = (controller.Get()->*action)();
144 ctx->GetResponse()->SetContentType(
"application/json");
155 auto controller = ResolveController(app, ctx);
157 return (controller.Get()->*action)(id);
163 template <
typename TResult,
typename = std::enable_if_t<!std::is_same_v<TResult, DotNetDupe::System::String>>>
166 auto controller = ResolveController(app, ctx);
168 auto result = (controller.Get()->*action)(id);
169 ctx->GetResponse()->SetContentType(
"application/json");
176 template <
typename TResult,
typename TString,
typename = std::enable_if_t<!std::is_same_v<TResult, DotNetDupe::System::String> && std::is_same_v<std::decay_t<TString>, DotNetDupe::System::String>>>
179 auto controller = ResolveController(app, ctx);
183 size_t pageSize = 20;
186 if (ctx->GetRequest()->GetQuery().TryGetValue(
"page", sPage) || ctx->GetRequest()->GetRouteValues().TryGetValue(
"page", sPage)) {
189 if (ctx->GetRequest()->GetQuery().TryGetValue(
"pageSize", sPageSize) || ctx->GetRequest()->GetRouteValues().TryGetValue(
"pageSize", sPageSize)) {
193 auto result = (controller.Get()->*action)(channelName, page, pageSize);
194 ctx->GetResponse()->SetContentType(
"application/json");
203 template <
typename TResource>
207 auto controller = ResolveController(app, ctx);
208 auto body = ctx->GetRequest()->GetBody();
209 TResource payload = DotNetDupe::System::Text::Json::JsonSerializer::template Deserialize<TResource>(body);
210 return (controller.Get()->*action)(payload);
212 ctx->GetResponse()->SetStatusCode(400);
213 ctx->GetResponse()->SetContentType(
"application/json");
221 template <
typename TResource,
typename = std::enable_if_t<!std::is_reference_v<TResource>>>
225 auto controller = ResolveController(app, ctx);
226 auto body = ctx->GetRequest()->GetBody();
227 TResource payload = DotNetDupe::System::Text::Json::JsonSerializer::template Deserialize<TResource>(body);
228 return (controller.Get()->*action)(payload);
230 ctx->GetResponse()->SetStatusCode(400);
231 ctx->GetResponse()->SetContentType(
"application/json");
239 template <
typename TResult,
typename TResource,
typename = std::enable_if_t<!std::is_same_v<TResult, DotNetDupe::System::String>>>
243 auto controller = ResolveController(app, ctx);
244 auto body = ctx->GetRequest()->GetBody();
245 TResource payload = DotNetDupe::System::Text::Json::JsonSerializer::template Deserialize<TResource>(body);
246 auto result = (controller.Get()->*action)(payload);
247 ctx->GetResponse()->SetContentType(
"application/json");
250 ctx->GetResponse()->SetStatusCode(400);
251 ctx->GetResponse()->SetContentType(
"application/json");
259 template <
typename TResult,
typename TResource,
typename = std::enable_if_t<!std::is_same_v<TResult, DotNetDupe::System::String> && !std::is_reference_v<TResource>>>
263 auto controller = ResolveController(app, ctx);
264 auto body = ctx->GetRequest()->GetBody();
265 TResource payload = DotNetDupe::System::Text::Json::JsonSerializer::template Deserialize<TResource>(body);
266 auto result = (controller.Get()->*action)(payload);
267 ctx->GetResponse()->SetContentType(
"application/json");
270 ctx->GetResponse()->SetStatusCode(400);
271 ctx->GetResponse()->SetContentType(
"application/json");
281 template <
typename TResource>
285 auto controller = ResolveController(app, ctx);
287 auto body = ctx->GetRequest()->GetBody();
288 TResource payload = DotNetDupe::System::Text::Json::JsonSerializer::template Deserialize<TResource>(body);
289 return (controller.Get()->*action)(id, payload);
291 ctx->GetResponse()->SetStatusCode(400);
292 ctx->GetResponse()->SetContentType(
"application/json");
300 template <
typename TResource,
typename = std::enable_if_t<!std::is_reference_v<TResource>>>
304 auto controller = ResolveController(app, ctx);
306 auto body = ctx->GetRequest()->GetBody();
307 TResource payload = DotNetDupe::System::Text::Json::JsonSerializer::template Deserialize<TResource>(body);
308 return (controller.Get()->*action)(id, payload);
310 ctx->GetResponse()->SetStatusCode(400);
311 ctx->GetResponse()->SetContentType(
"application/json");
319 template <
typename TResult,
typename TResource,
typename = std::enable_if_t<!std::is_same_v<TResult, DotNetDupe::System::String>>>
323 auto controller = ResolveController(app, ctx);
325 auto body = ctx->GetRequest()->GetBody();
326 TResource payload = DotNetDupe::System::Text::Json::JsonSerializer::template Deserialize<TResource>(body);
327 auto result = (controller.Get()->*action)(id, payload);
328 ctx->GetResponse()->SetContentType(
"application/json");
331 ctx->GetResponse()->SetStatusCode(400);
332 ctx->GetResponse()->SetContentType(
"application/json");
340 template <
typename TResult,
typename TResource,
typename = std::enable_if_t<!std::is_same_v<TResult, DotNetDupe::System::String> && !std::is_reference_v<TResource>>>
344 auto controller = ResolveController(app, ctx);
346 auto body = ctx->GetRequest()->GetBody();
347 TResource payload = DotNetDupe::System::Text::Json::JsonSerializer::template Deserialize<TResource>(body);
348 auto result = (controller.Get()->*action)(id, payload);
349 ctx->GetResponse()->SetContentType(
"application/json");
352 ctx->GetResponse()->SetStatusCode(400);
353 ctx->GetResponse()->SetContentType(
"application/json");
365 auto controller = ResolveController(app, ctx);
367 return (controller.Get()->*action)(id);
373 template <
typename TResult,
typename = std::enable_if_t<!std::is_same_v<TResult, DotNetDupe::System::String>>>
376 auto controller = ResolveController(app, ctx);
378 auto result = (controller.Get()->*action)(id);
379 ctx->GetResponse()->SetContentType(
"application/json");
387 for (
int i = 0; i < m_routes.GetCount(); ++i) {
388 const auto& r = m_routes[i];
389 if (r.Method ==
"GET") {
391 return r.Handler(app, ctx);
393 }
else if (r.Method ==
"POST") {
395 return r.Handler(app, ctx);
397 }
else if (r.Method ==
"PUT") {
399 return r.Handler(app, ctx);
401 }
else if (r.Method ==
"DELETE") {
403 return r.Handler(app, ctx);
Defines common cross-platform macros, export decorators, and fundamental types.
Converts a base data type to another base data type, and encodes/decodes Base64 data.
Encapsulates a method that has parameters and returns a value of the type specified by the TResult pa...
HTTP request, response, and context abstractions for WebAppCore processing pipelines.
Provides functionality to serialize objects to JSON strings and deserialize JSON strings into objects...
Represents a strongly typed list of objects that can be accessed by index mirroring ....
Base object class for DotNetDupe mirroring .NET System.Object.
Provides reference-counted and weak pointer memory management primitives ensuring zero raw ownership.
High-performance UTF-8 / UTF-16 string manipulation class mirroring .NET System.String.
Represents the web application used to configure the HTTP pipeline and routes mirroring ASP....
Represents a strongly typed list of objects accessible by index.
static int ToInt32(bool value)
Represents errors that occur during application execution.
const char * What() const
Gets a message that describes the current exception.
Primary template declaration for the Func delegate family.
Supports all classes in the DotNetDupe class hierarchy.
A unified smart pointer that supports both unique and shared ownership semantics.
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
String Substring(int iStartIndex) const
int IndexOf(const String &sSubstring) const
const char * GetRawString() const
static String Serialize(const T &value)
Converts the value of a type specified by a generic type parameter into a JSON string.
ControllerRouteBuilder(const DotNetDupe::System::String &prefix)
~ControllerRouteBuilder() override=default
ControllerRouteBuilder & MapPut(const DotNetDupe::System::String &subPath, DotNetDupe::System::String(TController::*action)(const DotNetDupe::System::String &, TResource))
ControllerRouteBuilder & MapPost(const DotNetDupe::System::String &subPath, DotNetDupe::System::String(TController::*action)(TResource))
ControllerRouteBuilder & MapPut(const DotNetDupe::System::String &subPath, TResult(TController::*action)(const DotNetDupe::System::String &, TResource))
ControllerRouteBuilder & MapPost(const DotNetDupe::System::String &subPath, TResult(TController::*action)(const TResource &))
ControllerRouteBuilder & MapPost(const DotNetDupe::System::String &subPath, TResult(TController::*action)(TResource))
ControllerRouteBuilder & MapDelete(const DotNetDupe::System::String &subPath, DotNetDupe::System::String(TController::*action)(const DotNetDupe::System::String &))
ControllerRouteBuilder & MapPut(const DotNetDupe::System::String &subPath, TResult(TController::*action)(const DotNetDupe::System::String &, const TResource &))
ControllerRouteBuilder & MapGet(const DotNetDupe::System::String &subPath, TResult(TController::*action)(const DotNetDupe::System::String &))
ControllerRouteBuilder & MapPut(const DotNetDupe::System::String &subPath, DotNetDupe::System::String(TController::*action)(const DotNetDupe::System::String &, const TResource &))
ControllerRouteBuilder & MapPost(const DotNetDupe::System::String &subPath, DotNetDupe::System::String(TController::*action)(const TResource &))
ControllerRouteBuilder & MapDelete(const DotNetDupe::System::String &subPath, TResult(TController::*action)(const DotNetDupe::System::String &))
void Register(const DotNetDupe::System::SmartPointer< Builder::WebApplication > &app) override
Registers the configured controller routes onto the target WebApplication.
ControllerRouteBuilder & MapGet(const DotNetDupe::System::String &subPath, TResult(TController::*action)(const TString &, size_t, size_t))
ControllerRouteBuilder & MapGet(const DotNetDupe::System::String &subPath, TResult(TController::*action)())
ControllerRouteBuilder & MapGet(const DotNetDupe::System::String &subPath, DotNetDupe::System::String(TController::*action)(const DotNetDupe::System::String &))
ControllerRouteBuilder & MapGet(const DotNetDupe::System::String &subPath, DotNetDupe::System::String(TController::*action)())
Interface for late-binding controller routes to a WebApplication instance.
virtual void Register(const DotNetDupe::System::SmartPointer< Builder::WebApplication > &app)=0
Registers the configured controller routes onto the target WebApplication.
virtual ~IControllerRouteRegistrar()=default
Virtual destructor.