New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get query parameters? #20
Comments
Hello @yoshihitoh ! Thank you for the question. I appreciate your interest in the project! Here is the example endpoint: ENDPOINT("GET", "example/path/{path-param}/query/*", getUserWithQueryParams,
REQUEST(std::shared_ptr<IncomingRequest>, request), // Map request object to endpoint method
PATH(String, pathParam, "path-param")) {
/* get url 'tail' - everything that comes after '*' */
String tail = request->getPathTail(); // everything that goes after '*'
/* check tail for null */
OATPP_ASSERT_HTTP(tail, Status::CODE_400, "null query-params");
/* parse query params from tail */
auto queryParams = oatpp::network::Url::Parser::parseQueryParams(tail);
/* get your param by name */
auto queryParameter = queryParams->get("param"/* parameter name */, "default-value" /* default value */);
/* return result */
return createResponse(Status::CODE_200, "path-param=" + pathParam + " query-param=" + queryParameter);
}
Currently you have to map Curls:
Your request will work in both cases with and without Regards, |
@lganzzzo Thanks for the detailed explanation! Many thanks, |
You are welcome Best Regards, |
Hi there!
I'm interested in to use oat++.
oatpp-examples works fine, really good to know how to use oat++!
Unfortunately, I couldn't find how to get the query parameters from endpoint defined on ApiController.
I saw that Url class has
queryParams
, so that I think query parameters are available on oat++.Please let me know how to get that.
Thanks.
The text was updated successfully, but these errors were encountered: