Start provides no pragmatic post parameter handling
nkratzke opened this issue · comments
Start provides no pragmatic parameter handling of post request. Therefore I propose the following method for class Request
.
/**
* Method to get post parameters from a [Request] object.
*/
Future<Map<String, String>> getPostParams({ Encoding enc: UTF8 }) {
Completer c = new Completer();
this.input.transform(const AsciiDecoder()).listen((content) {
final postParams = new Map.fromIterable(
content.split("&").map((kvs) => kvs.split("=")),
key: (kv) => Uri.decodeQueryComponent(kv[0], encoding: enc),
value: (kv) => Uri.decodeQueryComponent(kv[1], encoding: enc)
);
c.complete(postParams);
});
return c.future;
}
This would enable to do a pragmatic post parameter handling in start. Like this ...
app.post("/formular").listen((Request req) {
final name = req.getPostParams().then((params) {
final fn = params['first name'];
final ln = params['last name'];
req.response.send(renderForm("$fn $ln"));
});
});
Related to #47, I like your solution, will integrate it soon
Would be great ...
I think it's not only for POST
params, but also for PUT
ones. So I'll rename it to something more useful, like params
. Nevertheless, it looks, like it works now, thanks
Yeah I think the have requestParams() method to get all request parameters of any kind of request (put, get, delete, post) would be very useful. BTW: Thanks to integrate pragmatic cookie handling in requests with version 0.2.1 ;-)