digitalmars.D.announce - Vibe.d web interface tutorial
- aberba (2/2) Mar 09 2018 New blog post for the learning audience
- aberba (2/4) Mar 09 2018 http://aberba.com/2018/using-vibe-d-web-interface
- Martin Tschierschke (2/7) Mar 10 2018 Thank you! I linke it.
- aberba (3/11) Mar 12 2018 Glad you did.
- Steven Schveighoffer (15/22) Mar 13 2018 Very nice! Although this is missing one of my favorite vibe.d web
- Daniel Kozak (68/93) Mar 13 2018 On contrary I really hate that :D.
- Steven Schveighoffer (13/25) Mar 13 2018 That's not what I was talking about, I was talking about how the
- Daniel Kozak (3/29) Mar 13 2018 Yes PHP is always to blame :)
- aberba (5/29) Mar 13 2018 I can testify I've never written PHP code as clean as yours
- Nick Sabalausky (Abscissa) (3/5) Mar 13 2018 From my archives:
- aberba (7/30) Mar 13 2018 I don't know why but I dont really use that feature often. I tend
- Steven Schveighoffer (7/20) Mar 15 2018 I don't know, I haven't used it in that capacity.
New blog post for the learning audience aberba.com/2018/using-vibe-d-web-interface
Mar 09 2018
On Friday, 9 March 2018 at 16:32:28 UTC, aberba wrote:New blog post for the learning audience aberba.com/2018/using-vibe-d-web-interfacehttp://aberba.com/2018/using-vibe-d-web-interface
Mar 09 2018
On Friday, 9 March 2018 at 16:34:52 UTC, aberba wrote:On Friday, 9 March 2018 at 16:32:28 UTC, aberba wrote:Thank you! I linke it.New blog post for the learning audience aberba.com/2018/using-vibe-d-web-interfacehttp://aberba.com/2018/using-vibe-d-web-interface
Mar 10 2018
On Saturday, 10 March 2018 at 15:03:59 UTC, Martin Tschierschke wrote:On Friday, 9 March 2018 at 16:34:52 UTC, aberba wrote:Glad you did.On Friday, 9 March 2018 at 16:32:28 UTC, aberba wrote:Thank you! I linke it.New blog post for the learning audience aberba.com/2018/using-vibe-d-web-interfacehttp://aberba.com/2018/using-vibe-d-web-interface
Mar 12 2018
On 3/9/18 11:34 AM, aberba wrote:On Friday, 9 March 2018 at 16:32:28 UTC, aberba wrote:Very nice! Although this is missing one of my favorite vibe.d web interface features -- automatic parsing of route parameters: class WebInterface { void getRoute(HTTPServerResponse res, int foo, Nullable!int bar) { import std.format; res.writeBody(format("foo = %s, bar = %s", foo, bar)); } } /route => Error, foo required /route?foo=1 => "foo = 1, bar = Nullable.null" /route?foo=2&bar=5 => "foo = 1, bar = 5" -SteveNew blog post for the learning audience aberba.com/2018/using-vibe-d-web-interfacehttp://aberba.com/2018/using-vibe-d-web-interface
Mar 13 2018
On contrary I really hate that :D. Because of this: HTTP method Recognized prefixes GET get, query PUT set, put POST add, create, post DELETE remove, erase, delete PATCH update, patch I am calling vibed from PHP and I need to tweak my curl for every request baceuse of this :D public function sendRequest($method, $params = []) { $method = strtolower(preg_replace('/([^A-Z])([A-Z])/', "$1_$2", $method)); $isGetRequestType = substr($method, 0, 3) == 'get'; $isPutRequestType = substr($method, 0, 3) == 'set'; $httpHeader = $isGetRequestType ? [] : ['Content-Type: application/json']; if ($this->sessionId) { $httpHeader[] = "Cookie: vibe.session_id=" . $this->sessionId . "; Path=/; HttpOnly"; } if ($isGetRequestType) { $url = UrlBuilder::fromUrl($this->url)->appendPath(substr($method, 4)); $url->addParams($params); $curl = curl_init($url); curl_setopt_array($curl, [ CURLOPT_RETURNTRANSFER => 1, CURLOPT_HTTPHEADER => $httpHeader, CURLOPT_USERAGENT => EdiClient::USER_AGENT, CURLOPT_URL => $url->toString(), CURLOPT_RETURNTRANSFER => true ]); } elseif ($isPutRequestType) { $url = UrlBuilder::fromUrl($this->url)->appendPath(substr($method, 4)); $curl = curl_init($url); $json = json_encode($params); curl_setopt_array($curl, [ CURLOPT_RETURNTRANSFER => 1, CURLOPT_HTTPHEADER => $httpHeader, CURLOPT_USERAGENT => EdiClient::USER_AGENT, CURLOPT_URL => $url->toString(), CURLOPT_CUSTOMREQUEST => "PUT", CURLOPT_POSTFIELDS => $json, CURLOPT_RETURNTRANSFER => true ]); } else { $url = UrlBuilder::fromUrl($this->url)->appendPath($method); $curl = curl_init($url); $json = json_encode($params); curl_setopt_array($curl, [ CURLOPT_RETURNTRANSFER => 1, CURLOPT_HTTPHEADER => $httpHeader, CURLOPT_USERAGENT => EdiClient::USER_AGENT, CURLOPT_URL => $url->toString(), CURLOPT_POST => true, CURLOPT_POSTFIELDS => $json, CURLOPT_RETURNTRANSFER => true ]); } $result = curl_exec($curl); curl_close($curl); $result = json_decode($result, true); return $result; } On Tue, Mar 13, 2018 at 11:12 AM, Steven Schveighoffer via Digitalmars-d-announce <digitalmars-d-announce puremagic.com> wrote:On 3/9/18 11:34 AM, aberba wrote:On Friday, 9 March 2018 at 16:32:28 UTC, aberba wrote:Very nice! Although this is missing one of my favorite vibe.d web interface features -- automatic parsing of route parameters: class WebInterface { void getRoute(HTTPServerResponse res, int foo, Nullable!int bar) { import std.format; res.writeBody(format("foo = %s, bar = %s", foo, bar)); } } /route => Error, foo required /route?foo=1 => "foo = 1, bar = Nullable.null" /route?foo=2&bar=5 => "foo = 1, bar = 5" -SteveNew blog post for the learning audience aberba.com/2018/using-vibe-d-web-interfacehttp://aberba.com/2018/using-vibe-d-web-interface
Mar 13 2018
On 3/13/18 6:22 AM, Daniel Kozak wrote:On contrary I really hate that :D. Because of this: HTTP methodRecognized prefixes GETget, query PUTset, put POSTadd, create, post DELETEremove, erase, delete PATCHupdate, patch I am calling vibed from PHP and I need to tweak my curl for every request baceuse of this :DThat's not what I was talking about, I was talking about how the parameters are automatically parsed passed to the web functions. It doesn't affect how the routes are called externally, just how the parameters are dealt with. Note, you can override the method for any/all routes: class WebInterface { method(HTTPMethod.GET): ... // all methods are now get } I think perhaps the root cause of your problem is using PHP ;) -Steve
Mar 13 2018
Yes PHP is always to blame :) On Tue, Mar 13, 2018 at 1:55 PM, Steven Schveighoffer via Digitalmars-d-announce <digitalmars-d-announce puremagic.com> wrote:On 3/13/18 6:22 AM, Daniel Kozak wrote:On contrary I really hate that :D. Because of this: HTTP methodRecognized prefixes GETget, query PUTset, put POSTadd, create, post DELETEremove, erase, delete PATCHupdate, patch I am calling vibed from PHP and I need to tweak my curl for every request baceuse of this :DThat's not what I was talking about, I was talking about how the parameters are automatically parsed passed to the web functions. It doesn't affect how the routes are called externally, just how the parameters are dealt with. Note, you can override the method for any/all routes: class WebInterface { method(HTTPMethod.GET): ... // all methods are now get } I think perhaps the root cause of your problem is using PHP ;) -Steve
Mar 13 2018
On Tuesday, 13 March 2018 at 13:42:20 UTC, Daniel Kozak wrote:Yes PHP is always to blame :)I can testify I've never written PHP code as clean as yours above. Ha ha. Even when I used PHP heavily. I suck a lil bit at naming things. I really loved PHP but ... vibe.d happened.On Tue, Mar 13, 2018 at 1:55 PM, Steven Schveighoffer via Digitalmars-d-announce <digitalmars-d-announce puremagic.com> wrote:On 3/13/18 6:22 AM, Daniel Kozak wrote:[...]That's not what I was talking about, I was talking about how the parameters are automatically parsed passed to the web functions. It doesn't affect how the routes are called externally, just how the parameters are dealt with. Note, you can override the method for any/all routes: class WebInterface { method(HTTPMethod.GET): ... // all methods are now get } I think perhaps the root cause of your problem is using PHP ;) -Steve
Mar 13 2018
On 03/13/2018 09:42 AM, Daniel Kozak wrote:Yes PHP is always to blame :)From my archives: https://semitwist.com/articles/article/view/10-fun-facts-about-php
Mar 13 2018
On Tuesday, 13 March 2018 at 10:12:24 UTC, Steven Schveighoffer wrote:On 3/9/18 11:34 AM, aberba wrote:I don't know why but I dont really use that feature often. I tend to access them with req.query.get("param") and req.form.get("param") directly. Don't know why... time to save some key strokes. ...but how does file handling work with this approach? input(type="file"...)On Friday, 9 March 2018 at 16:32:28 UTC, aberba wrote:Very nice! Although this is missing one of my favorite vibe.d web interface features -- automatic parsing of route parameters: class WebInterface { void getRoute(HTTPServerResponse res, int foo, Nullable!int bar) { import std.format; res.writeBody(format("foo = %s, bar = %s", foo, bar)); } } /route => Error, foo required /route?foo=1 => "foo = 1, bar = Nullable.null" /route?foo=2&bar=5 => "foo = 1, bar = 5" -SteveNew blog post for the learning audience aberba.com/2018/using-vibe-d-web-interfacehttp://aberba.com/2018/using-vibe-d-web-interface
Mar 13 2018
On 3/13/18 4:42 PM, aberba wrote:On Tuesday, 13 March 2018 at 10:12:24 UTC, Steven Schveighoffer wrote:I don't know, I haven't used it in that capacity. The reason why I like it is because it validates the text for you (in cases where you aren't looking for strings), and because it feels more like calling a function from a browser rather than a protocol parsing exercise ;) -SteveOn 3/9/18 11:34 AM, aberba wrote:I don't know why but I dont really use that feature often. I tend to access them with req.query.get("param") and req.form.get("param") directly. Don't know why... time to save some key strokes. ...but how does file handling work with this approach? input(type="file"...)http://aberba.com/2018/using-vibe-d-web-interfaceVery nice! Although this is missing one of my favorite vibe.d web interface features -- automatic parsing of route parameters:
Mar 15 2018