Home  /  Documentation  /  Examples  /  QS demo

QS demo

This is a simple 2-pages application demonstrating QS macro usage to get a value provided by client in the query string.

QS works with all popular HTTP methods and payload types.

npp_app.cpp

void npp_app_main() { if ( REQ("") ) // landing page { OUT_HTML_HEADER; // generic HTML header with opening body tag OUT("<h1>%s</h1>", NPP_APP_NAME); OUT("<h2>Welcome to my web app!</h2>"); /* show client type */ if ( REQ_DSK ) OUT("<p>You're on desktop, right?</p>"); else if ( REQ_TAB ) OUT("<p>You're on tablet, right?</p>"); else /* REQ_MOB */ OUT("<p>You're on the phone, right?</p>"); /* link to welcome */ OUT("<p>Click <a href=\"/welcome\">here</a> to try my welcoming bot.</p>"); OUT_HTML_FOOTER; // body and html closing tags } else if ( REQ("welcome") ) // welcoming bot { OUT_HTML_HEADER; OUT("<h1>%s</h1>", NPP_APP_NAME); /* display form */ OUT("<p>Please enter your name:</p>"); OUT("<form action=\"welcome\"><input name=\"name\" autofocus> <input type=\"submit\" value=\"Run\"></form>"); /* try to get the query string value */ QSVAL qs_name; // query string value if ( QS("name", qs_name) ) // if present, bid welcome OUT("<p>Welcome %s, my dear friend!</p>", qs_name); OUT("<p><a href=\"/\">Back to landing page</a></p>"); OUT_HTML_FOOTER; } else // page not found { RES_STATUS(404); } }