Thread overview | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
March 09, 2018 Vibe.d web interface tutorial | ||||
---|---|---|---|---|
| ||||
New blog post for the learning audience aberba.com/2018/using-vibe-d-web-interface |
March 09, 2018 Re: Vibe.d web interface tutorial | ||||
---|---|---|---|---|
| ||||
Posted in reply to aberba | 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-interface http://aberba.com/2018/using-vibe-d-web-interface |
March 10, 2018 Re: Vibe.d web interface tutorial | ||||
---|---|---|---|---|
| ||||
Posted in reply to aberba | On Friday, 9 March 2018 at 16:34:52 UTC, aberba wrote:
> 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-interface
>
> http://aberba.com/2018/using-vibe-d-web-interface
Thank you! I linke it.
|
March 12, 2018 Re: Vibe.d web interface tutorial | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin Tschierschke | 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:
>> 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-interface
>>
>> http://aberba.com/2018/using-vibe-d-web-interface
>
> Thank you! I linke it.
Glad you did.
|
March 13, 2018 Re: Vibe.d web interface tutorial | ||||
---|---|---|---|---|
| ||||
Posted in reply to aberba | On 3/9/18 11:34 AM, aberba wrote:
> 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-interface
>
> http://aberba.com/2018/using-vibe-d-web-interface
>
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"
-Steve
|
March 13, 2018 Re: Vibe.d web interface tutorial | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer Attachments:
| 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: >> >>> New blog post for the learning audience >>> >>> aberba.com/2018/using-vibe-d-web-interface >>> >> >> http://aberba.com/2018/using-vibe-d-web-interface >> >> > 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" > > -Steve > |
March 13, 2018 Re: Vibe.d web interface tutorial | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Kozak | 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 :D
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
|
March 13, 2018 Re: Vibe.d web interface tutorial | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer Attachments:
| 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 :D >> > > 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 > |
March 13, 2018 Re: Vibe.d web interface tutorial | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Kozak | 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 |
March 13, 2018 Re: Vibe.d web interface tutorial | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Tuesday, 13 March 2018 at 10:12:24 UTC, Steven Schveighoffer wrote:
> On 3/9/18 11:34 AM, aberba wrote:
>> 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-interface
>>
>> http://aberba.com/2018/using-vibe-d-web-interface
>>
>
> 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"
>
> -Steve
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"...)
|
Copyright © 1999-2021 by the D Language Foundation