Stiffstream / restinio

Cross-platform, efficient, customizable, and robust asynchronous HTTP(S)/WebSocket server C++ library with the right balance between performance and ease of use
Other
1.13k stars 92 forks source link

How to extract params with tab #138

Closed noctera closed 3 years ago

noctera commented 3 years ago

Good evening I have this lines of code

router->http_get("/api/signIn&username=:param&sessionId=:session", [](auto req, auto params) {
        const auto id = restinio::cast_to<std::string>(params["param"]);
        std::cout << id << std::endl;

        return init_resp(req->create_response())
            .set_body(
                fmt::format(
                    "Username: '{}'\nSessionId: '{}'",
                    params["param"],
                    params["session"]))
            .done();
    });

With

http://127.0.0.1:13200/api/signIn&username=John%20Doe&sessionId=session

I am making the request call, but unfortunately I am getting John%20Doe out of the params list. Is there any function I can make it to John Doe with an intern function, or do I have to program that.

PS: Google is automatically filling in %20 for a tab

Thanks in advance

eao197 commented 3 years ago

Hi!

It seems that you discovered a flaw in RESTinio's implementation, named parameters like :param and :session are intended to be used in the path part of URL, e.g. inside /api/signIn before the & sign. Values in the query part of URL (after the & sign) should be parsed and accessed via parse_query or try_parse_query functions (see the docs).

eao197 commented 3 years ago

It also seems that your URL should look like /api/signIn?username=John&sessionId=Bla-Bla-Bla

noctera commented 3 years ago

Yeah my url should look like this. I will have a look at the doc you linked above

noctera commented 3 years ago

I will close this issue, as it is the same problem like in my other issue tab. Will go on #139