You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Minimal working changes (No Query or Header or Path Parameters handelling)
Resolved include names and generated file names.
Adjusted mustache files and aligned properly.
Added NLOHMANN_DEFINE_TYPE_INTRUSIVE for json serialization and deserialization.
auto <your_api>Impl = std::make_shared<YourApiImpl>();
146
127
147
128
// Register routes
148
-
apiImpl->registerRoutes(svr);
129
+
<your_api>Impl->RegisterRoutes(std::move(svr));
149
130
150
131
// Start server on port 8080
151
-
svr.listen("localhost", 8080);
132
+
svr->listen("localhost", 8080);
152
133
153
134
return 0;
154
135
}
155
136
```
156
137
157
138
## Error Handling
158
139
140
+
159
141
Each API endpoint returns a `std::variant` type that can hold either a success response or one of several error responses.
160
142
The server automatically handles this variant and returns the appropriate HTTP status code and JSON body using the generated helper functions.
161
143
162
144
For each response type (success or error), a corresponding status code constant (e.g., `MYRESPONSE_200`, `MYERROR_400`) is generated and used by the server when returning that type. You do not need to set the status code manually; just return the appropriate type from your handler.
163
145
164
-
Error handling for invalid parameters or JSON is performed automatically in the generated route registration code. The server includes automatic handling for:
165
-
166
-
- Invalid JSON in request body
167
-
- Type errors in request parameters
168
-
- Invalid arguments (e.g., trying to parse a non-numeric string as a number)
169
-
- Out-of-range values
170
-
- Missing required parameters
171
-
172
-
You can customize error responses by returning the appropriate error type from your handler.
146
+
Error handling for invalid parameters or JSON is performed automatically in the generated route registration code. You can customize error responses by returning the appropriate error type from your handler.
173
147
174
148
## Working with Optional Fields
175
149
@@ -184,44 +158,18 @@ if (model.getOptionalField()) {
184
158
}
185
159
```
186
160
187
-
## Parameter Handling
188
-
189
-
### Path Parameters
190
-
191
-
Path parameters are extracted directly from URL path segments:
192
-
193
-
```cpp
194
-
// For a path like /users/{userId}/items/{itemId}
195
-
auto userId = params.m_userId; // Value from URL path
196
-
auto itemId = params.m_itemId; // Value from URL path
197
-
```
198
-
199
-
### Query Parameters
200
-
201
-
Query parameters are extracted from the URL query string:
202
-
203
-
```cpp
204
-
// For a URL like /users?filter=active&limit=10
205
-
auto filter = params.m_filter; // "active"
206
-
auto limit = params.m_limit; // 10
207
-
```
208
-
209
-
### Header Parameters
210
-
211
-
Header parameters are extracted from HTTP request headers:
212
-
213
-
```cpp
214
-
// For a header like "Authorization: Bearer token123"
215
-
auto auth = params.m_authorization; // "Bearer token123"
216
-
```
217
-
218
-
### Enum Parameters
219
-
220
-
Enum parameters (in path, query, or header) are automatically converted to their enum type:
0 commit comments