mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
added creating qs from request body functionality + updated doc
This commit is contained in:
parent
8bc0a4d939
commit
387c222ea2
@ -12,7 +12,7 @@
|
||||
|
||||
## Description
|
||||
|
||||
Crow is a C++ microframework for running web services. It uses routing similar to Python's Flask which makes it easy to use. It is also extremely fast, beating multiple existing C++ frameworks as well as non C++ frameworks.
|
||||
Crow is a C++ framework for creating HTTP or Websocket web services. It uses routing similar to Python's Flask which makes it easy to use. It is also extremely fast, beating multiple existing C++ frameworks as well as non C++ frameworks.
|
||||
|
||||
### Features
|
||||
- Easy Routing (similar to flask).
|
||||
@ -27,6 +27,7 @@ Crow is a C++ microframework for running web services. It uses routing similar t
|
||||
- Uses modern C++ (11/14)
|
||||
|
||||
### Still in development
|
||||
- [Async support](https://github.com/CrowCpp/Crow/issues/258)
|
||||
- [HTTP/2 support](https://github.com/crowcpp/crow/issues/8)
|
||||
|
||||
## Documentation
|
||||
|
@ -2,6 +2,11 @@ A query string is the part of the URL that comes after a `?` character, it is us
|
||||
<br><br>
|
||||
|
||||
Crow supports query strings through `crow::request::url_params`. The object is of type `crow::query_string` and can has the following functions:<br>
|
||||
|
||||
!!! note "Note <span class="tag">[:octicons-feed-tag-16: master](https://github.com/CrowCpp/Crow)</span>"
|
||||
|
||||
A query string can be created from a Crow request or a url string. using the request will use the request body, which is useful for requests of type `application/x-www-form-urlencoded`.
|
||||
|
||||
## get(name)
|
||||
Returns the value (as char*) based on the given key (or name). Returns `nullptr` if the key is not found.
|
||||
## pop(name)
|
||||
|
@ -6,7 +6,7 @@
|
||||
<meta property="og:title" content="CrowCpp"/>
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:description" content="A Fast and Easy to use microframework for the web."/>
|
||||
<meta name="description" content="Crow is a C++ microframework for running web services. It uses routing similar to Python's Flask which makes it easy to use. It is also extremely fast, beating multiple existing C++ frameworks as well as non C++ frameworks.">
|
||||
<meta name="description" content="Crow is a C++ framework for creating HTTP or Websocket web services. It uses routing similar to Python's Flask which makes it easy to use. It is also extremely fast, beating multiple existing C++ frameworks as well as non C++ frameworks.">
|
||||
<meta property="og:image" content="assets/og_img.png" />
|
||||
<meta property="og:url" content="https://crowcpp.org">
|
||||
<meta property="twitter:card" content="summary_large_image">
|
||||
@ -148,6 +148,8 @@ code{
|
||||
|
||||
<h1 style="text-align:center;">A Fast and Easy to use microframework for the web.</h1>
|
||||
|
||||
<hr>
|
||||
<p style="text-align:center;">Crow is a C++ framework for creating HTTP or Websocket web services. It uses routing similar to Python's Flask which makes it easy to use. It is also extremely fast, beating multiple existing C++ frameworks as well as non C++ frameworks.</p>
|
||||
<hr>
|
||||
|
||||
<section class="csection">
|
||||
@ -178,7 +180,7 @@ code{
|
||||
|
||||
<section class="ssection">
|
||||
<div class="sdescription">
|
||||
<h2 style="text-align: center;">Easy to get started</h3>
|
||||
<h2 style="text-align: center;">Easy to get started</h2>
|
||||
</div>
|
||||
<div class="scontent">
|
||||
<div class="highlight"><pre id="__code_0"><span></span><button class="md-clipboard md-icon" title="Copy to clipboard" data-clipboard-target="#__code_0 > code"></button><code><span class="cp">#include</span> <span class="cpf">"crow.h"</span><span class="cp"></span>
|
||||
@ -208,14 +210,14 @@ code{
|
||||
</code></pre></div>
|
||||
</div>
|
||||
<div class="sdescription">
|
||||
<h2 style="text-align: center;">JSON Support Built-in</h3>
|
||||
<h2 style="text-align: center;">JSON Support Built-in</h2>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
<section class="ssection">
|
||||
<div class="sdescription">
|
||||
<h2 style="text-align: center;">URL parameter support as well!</h3>
|
||||
<h2 style="text-align: center;">URL parameter support as well!</h2>
|
||||
</div>
|
||||
<div class="scontent">
|
||||
<div class="highlight"><pre id="__code_2"><span></span><button class="md-clipboard md-icon" title="Copy to clipboard" data-clipboard-target="#__code_2 > code"></button><code><span class="cp">CROW_ROUTE</span><span class="p">(</span><span class="n">app</span><span class="p">,</span><span class="s">"/hello/<int>"</span><span class="p">)</span>
|
||||
|
@ -8,8 +8,11 @@
|
||||
#include <iostream>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include "crow/http_request.h"
|
||||
|
||||
namespace crow
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// qs_parse (modified)
|
||||
// https://github.com/bartgrantham/qs_parse
|
||||
@ -22,7 +25,7 @@ int qs_strncmp(const char * s, const char * qs, size_t n);
|
||||
* Also decodes the value portion of the k/v pair *in-place*. In a future
|
||||
* enhancement it will also have a compile-time option of sorting qs_kv
|
||||
* alphabetically by key. */
|
||||
int qs_parse(char * qs, char * qs_kv[], int qs_kv_size);
|
||||
int qs_parse(char * qs, char * qs_kv[], int qs_kv_size, bool parse_url);
|
||||
|
||||
|
||||
/* Used by qs_parse to decode the value portion of a k/v pair */
|
||||
@ -96,7 +99,7 @@ inline int qs_strncmp(const char * s, const char * qs, size_t n)
|
||||
}
|
||||
|
||||
|
||||
inline int qs_parse(char * qs, char * qs_kv[], int qs_kv_size)
|
||||
inline int qs_parse(char * qs, char * qs_kv[], int qs_kv_size, bool parse_url = true)
|
||||
{
|
||||
int i, j;
|
||||
char * substr_ptr;
|
||||
@ -104,7 +107,7 @@ inline int qs_parse(char * qs, char * qs_kv[], int qs_kv_size)
|
||||
for(i=0; i<qs_kv_size; i++) qs_kv[i] = NULL;
|
||||
|
||||
// find the beginning of the k/v substrings or the fragment
|
||||
substr_ptr = qs + strcspn(qs, "?#");
|
||||
substr_ptr = parse_url ? qs + strcspn(qs, "?#") : qs;
|
||||
if (substr_ptr[0] != '\0')
|
||||
substr_ptr++;
|
||||
else
|
||||
@ -343,6 +346,18 @@ namespace crow
|
||||
key_value_pairs_.resize(count);
|
||||
}
|
||||
|
||||
query_string(request req)
|
||||
: url_(req.body)
|
||||
{
|
||||
if (url_.empty())
|
||||
return;
|
||||
|
||||
key_value_pairs_.resize(MAX_KEY_VALUE_PAIRS_COUNT);
|
||||
|
||||
int count = qs_parse(&url_[0], &key_value_pairs_[0], MAX_KEY_VALUE_PAIRS_COUNT, false);
|
||||
key_value_pairs_.resize(count);
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
key_value_pairs_.clear();
|
||||
|
Loading…
Reference in New Issue
Block a user