Thread overview
vib.d suppress 404 for no content written
Feb 14, 2018
Nicholas Wilson
Feb 14, 2018
Seb
Feb 14, 2018
Nicholas Wilson
Feb 14, 2018
aberba
Feb 14, 2018
Seb
February 14, 2018
I have an endpoint that is a post:

void postStuff(HTTPServerRequest req, HTTPServerResponse res)
{
    // do some stuff with req
    res.statusCode = 200;
}

I do not write anything to res (deliberately) but want to set the status code.

However it returns 404, because no content is written.
How can I make it return 200?

FWIW its a member of a web interface class.

Thanks
Nic
February 14, 2018
On Wednesday, 14 February 2018 at 14:30:19 UTC, Nicholas Wilson wrote:
> I have an endpoint that is a post:
>
> void postStuff(HTTPServerRequest req, HTTPServerResponse res)
> {
>     // do some stuff with req
>     res.statusCode = 200;
> }
>
> I do not write anything to res (deliberately) but want to set the status code.
>
> However it returns 404, because no content is written.
> How can I make it return 200?
>
> FWIW its a member of a web interface class.
>
> Thanks
> Nic

You mean `writeVoidBody`

See Also: https://github.com/vibe-d/vibe.d/issues/2065

February 14, 2018
On Wednesday, 14 February 2018 at 14:58:14 UTC, Seb wrote:
> On Wednesday, 14 February 2018 at 14:30:19 UTC, Nicholas Wilson wrote:
>> I have an endpoint that is a post:
>>
>> void postStuff(HTTPServerRequest req, HTTPServerResponse res)
>> {
>>     // do some stuff with req
>>     res.statusCode = 200;
>> }
>>
>> I do not write anything to res (deliberately) but want to set the status code.
>>
>> However it returns 404, because no content is written.
>> How can I make it return 200?
>>
>> FWIW its a member of a web interface class.
>>
>> Thanks
>> Nic
>
> You mean `writeVoidBody`
>
> See Also: https://github.com/vibe-d/vibe.d/issues/2065

Thanks!
February 14, 2018
On Wednesday, 14 February 2018 at 14:58:14 UTC, Seb wrote:
> On Wednesday, 14 February 2018 at 14:30:19 UTC, Nicholas Wilson wrote:
>> I have an endpoint that is a post:
>>
>> void postStuff(HTTPServerRequest req, HTTPServerResponse res)
>> {
>>     // do some stuff with req
>>     res.statusCode = 200;
>> }
>>
>> I do not write anything to res (deliberately) but want to set the status code.
>>
>> However it returns 404, because no content is written.
>> How can I make it return 200?
>>
>> FWIW its a member of a web interface class.
>>
>> Thanks
>> Nic
>
> You mean `writeVoidBody`
>
> See Also: https://github.com/vibe-d/vibe.d/issues/2065

Seb,  are you the one doing the vibe.d demo collections?
February 14, 2018
On Wednesday, 14 February 2018 at 21:16:23 UTC, aberba wrote:
> Seb,  are you the one doing the vibe.d demo collections?

Do you mean this?

https://github.com/wilzbach/vibe-d-by-example

Yes, that's me, but it still needs a lot of work and I haven't got around polishing it for an alpha "release", but the examples there should be fully functional with ~>vibe.d-0.8.3-alpha.1

BTW I also have a fork of vibe.web.web at https://github.com/teamhackback/hb-web which adds all the convenience features that I haven't been able to get upstream so far [1].
A short overview of what I miss in vibe.web.web:

---
class Service {

    // Returning strings (instead of res.writeBody)
    string getString() { return "string"; } // https://github.com/vibe-d/vibe.d/pull/1854

    // Access to Json
    auto postJson(Json _json) { return _json; } // https://github.com/vibe-d/vibe.d/pull/1853

    // Automatically serialize data types
    auto postStruct(MyStruct st) { return st.foo + 3; } // https://github.com/vibe-d/vibe.d/pull/1697

    // https://github.com/vibe-d/vibe.d/pull/1698
    // @path is automatically set to /user/:id
    // works for all _-prefixed variables that don't have any inference yet (i.e. _error still works)
    void getUser(string _id, HTTPServerResponse res) {
        res.writeBody("User: " ~ _id);
    }
}
---


Though to be fair, things improved a bit in Vibe.d 0.8.2 and `request` and `response` are now available.
They refer to current request.


[1] https://github.com/vibe-d/vibe.d/pulls/wilzbach