ipkn / crow

Crow is very fast and easy to use C++ micro web framework (inspired by Python Flask)
BSD 3-Clause "New" or "Revised" License
7.47k stars 888 forks source link

Crow server to receive HTTP (POST, GET) and return JSON? #301

Open Outstep opened 6 years ago

Outstep commented 6 years ago

Hello,

I am a bit new to IPKN/CROW but it seems to be extremely fast and efficient.

What I would like to do with it is to be able send it, in a multi-thread serve)

curl "http://localhost:8888/?q=solar%20panels&categories=general&format=json&lang=en&pageno=1"

Break the query a part into c++ user variables:

q=solar%20panels categories=general format=json lang=en pageno=1

and then be able to perhaps use an additional framework to structure a JSON output to return.

Crow seems to be very fast from my initial tests and the json input works great, but I would like to see if it is still possible to use this framework as reading through the github issues suggests that it "might" be possible, but I not sure how to move forward and cannot locate any type of related examples.

Any help would be truly appreciated. Thanks

mrozigor commented 6 years ago

It looks like you can access URL params with something like this:

CROW_ROUTE(app, "/request") ([](const crow::request& req){ auto q = req.url_params.get("q"); // GET PARAMETERS return crow::response{os.str()}; // RETURN JSON AS IN EXAMPLES });

Example is based on source code, I didn't test it ;) Hope it helps.