Comments (4)
Thanks very much. It works perfectly!
from oatpp.
Hello @Vi-vi-Vi ,
Thank you for the question and your interest in the project!
Please see the examples:
Add query parameter manually
ENDPOINT_INFO(getComputedValues) {
// general
info->summary = "Compute values corresponding to the input parameters";
info->addResponse<UserDto::ObjectWrapper>(Status::CODE_200, "application/json");
info->addResponse<String>(Status::CODE_404, "text/plain");
// params specific
info->queryParams.add<String>("param1").description = "Input value 1"; // add query parameter manually
info->queryParams.add<String>("param2").description = "Input value 2"; // add query parameter manually
info->queryParams.add<String>("param3"); // add query parameter with no description manually
info->queryParams["param3"].required = false; // make parameter optional
}
ENDPOINT("GET", "compute/*", getComputedValues,
REQUEST(std::shared_ptr<IncomingRequest>, request) // Map request object to endpoint method
) {
auto p1 = request->getQueryParameter("param1", "" /* default value */);
auto p2 = request->getQueryParameter("param2", "" /* default value */);
auto p3 = request->getQueryParameter("param3", "" /* default value */);
OATPP_LOGD("Endpoint", "p1=%s, p2=%s, p3=%s", p1->getData(), p2->getData(), p3->getData());
return createResponse(Status::CODE_200, "ok");
}
Add query parameters by mapping param to a method variable
ENDPOINT_INFO(getComputedValues2) {
// general
info->summary = "Compute values corresponding to the input parameters";
info->addResponse<UserDto::ObjectWrapper>(Status::CODE_200, "application/json");
info->addResponse<String>(Status::CODE_404, "text/plain");
// params specific
info->queryParams["param1"].description = "Input value 1";
info->queryParams["param2"].description = "Input value 2";
info->queryParams["my-param-name"].description = "Input value 3";
}
ENDPOINT("GET", "compute2/*", getComputedValues2,
QUERY(String, param1), // Add query parameters by mapping param to a method variable
QUERY(String, param2),
QUERY(String, param3, "my-param-name") // query param with name qualifier
) {
OATPP_LOGD("Endpoint", "p1=%s, p2=%s, p3=%s", param1->getData(), param2->getData(), param3->getData());
return createResponse(Status::CODE_200, "ok");
}
Please let me know if you have more questions.
Best Regards,
Leonid
from oatpp.
Is this possible for repeating query params?
Such as ?status=1&status=2&status=3
Since the number of repeating params can be variable, can swagger handle this?
from oatpp.
Hey @acidtonic ,
Not yet. At the moment you can't parse query params as an array of values.
from oatpp.
Related Issues (20)
- Enhance Deserializer's "Error. Unknown field"
- How can I use OATPP to handle web browser request download file. HOT 2
- Memory leak in Object mapping HOT 1
- Deserialize json when not include required field only gives error when the field is specified as null
- [Question] readBodyIntoDTO when there's a list in the body
- API question
- how to make dynamic sql use oatpp-sqlite HOT 1
- LazyStringMapTemplate::get returns Nullptr wich is not in oatpp.io Documentation
- Please add support for CMake 3.16
- Cannot test if required integer query parameter is empty
- [Question] Is it possible during compilation to write out the generated oas-3.0.0.json file?
- May memory leak
- How should I make my process send requests to the target when using OATPP HOT 4
- Stack corruption issue in ConnectionProvider.cpp
- Can not build project successfully
- Is it possible make oatpp::network::tcp::client::ConnectionProvider support bind client IP?
- specific async pattern implementation query HOT 4
- io_uring support request HOT 1
- Compilation error on Windows with MinGW
- Facing linker issue (undefined reference to `oatpp::base::Environment::getComponent) in windows using mingw gcc compiler
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oatpp.