RejectedSoftware Forums

Sign up

HTTPServerRequest constructor is not callable

Hello

I have example code which is looking like below:

import std.algorithm, std.array;

@path("/api/integration")
interface IfWhiteBlowerAPI
{
    Json get() @safe;
    void postDeaf(HTTPServerRequest req, HTTPServerResponse res) @safe;
}


class WhiteBlowerAPI : IfWhiteBlowerAPI
{
  
  this(MongoCollection tmp)
  {
      collect = tmp;
  }


  private:
    MongoCollection collect;

  public: 
    Json get()
    {
      logInfo("Getting HomePage from DB");
      Bson query = Bson( [ "integration.configHash" : Bson(["$exists" : Bson("true")]) ]);
      auto result = collect.find(query);

      logInfo("Sending JSON");
      return Json(result.map!(a => a.toJson).array);
    }

    void postDeaf(HTTPServerRequest req, HTTPServerResponse res)
    {
      logInfo("Recived data:\n");

    }

}

but im getting such errors:

../../.dub/packages/vibe-d-0.8.0/vibe-d/data/vibe/data/serialization.d(649,37): Error: constructor vibe.http.server.HTTPServerRequest.this (SysTime time, ushort port) is not callable using argument types ()
Deserializing composite type CookieValueMap which has no serializable fields.
Deserializing composite type VariantN!32LU which has no serializable fields.
../../.dub/packages/vibe-d-0.8.0/vibe-d/data/vibe/data/serialization.d(547,114): Error: @safe function 'vibe.data.serialization.deserializeValueImpl!(JsonSerializer, DefaultPolicy).deserializeValue!(VariantN!32LU).deserializeValue' cannot call @system function 'vibe.data.serialization.deserializeValueImpl!(JsonSerializer, DefaultPolicy).deserializeValueDeduced!(VariantN!32LU).deserializeValueDeduced'
../../.dub/packages/vibe-d-0.8.0/vibe-d/data/vibe/data/serialization.d(690,47): Error: template instance vibe.data.serialization.deserializeValueImpl!(JsonSerializer, DefaultPolicy).deserializeValue!(VariantN!32LU) error instantiating
../../.dub/packages/vibe-d-0.8.0/vibe-d/data/vibe/data/serialization.d(676,31):        instantiated from here: __lambda2!string
../../.dub/packages/vibe-d-0.8.0/vibe-d/data/vibe/data/serialization.d(547,114):        instantiated from here: deserializeValueDeduced!(FieldTuple)
../../.dub/packages/vibe-d-0.8.0/vibe-d/data/vibe/data/serialization.d(597,15):        instantiated from here: deserializeValue!(FieldTuple)
../../.dub/packages/vibe-d-0.8.0/vibe-d/data/vibe/data/serialization.d(547,114):        ... (10 instantiations, -v to show) ...
../../.dub/packages/vibe-d-0.8.0/vibe-d/web/vibe/web/rest.d(99,45):        instantiated from here: jsonMethodHandler!(postDeaf, 1LU, WhiteBlowerAPI)
source/app.d(14,30):        instantiated from here: registerRestInterface!(WhiteBlowerAPI)
../../.dub/packages/vibe-d-0.8.0/vibe-d/data/vibe/data/serialization.d(676,30): Error: function vibe.data.json.JsonSerializer.readDictionary!(Traits!(FieldTuple, DefaultPolicy)).readDictionary (scope void delegate(string) @safe field_handler) is not callable using argument types (void)
../../.dub/packages/vibe-d-0.8.0/vibe-d/data/vibe/data/serialization.d(559,4): Error: function vibe.data.serialization.deserializeValueImpl!(JsonSerializer, DefaultPolicy).deserializeValueDeduced!(FieldTuple).deserializeValueDeduced no return exp; or assert(0); at end of function
../../.dub/packages/vibe-d-0.8.0/vibe-d/data/vibe/data/serialization.d(547,114): Error: @safe function 'vibe.data.serialization.deserializeValueImpl!(JsonSerializer, DefaultPolicy).deserializeValue!(FieldTuple).deserializeValue' cannot call @system function 'vibe.data.serialization.deserializeValueImpl!(JsonSerializer, DefaultPolicy).deserializeValueDeduced!(FieldTuple).deserializeValueDeduced'
../../.dub/packages/vibe-d-0.8.0/vibe-d/data/vibe/data/serialization.d(547,114): Error: @safe function 'vibe.data.serialization.deserializeValueImpl!(JsonSerializer, DefaultPolicy).deserializeValue!(DictionaryList!(VariantN!32LU, true, 2LU, false)).deserializeValue' cannot call @system function 'vibe.data.serialization.deserializeValueImpl!(JsonSerializer, DefaultPolicy).deserializeValueDeduced!(DictionaryList!(VariantN!32LU, true, 2LU, false)).deserializeValueDeduced'
../../.dub/packages/vibe-d-0.8.0/vibe-d/data/vibe/data/serialization.d(712,10): Error: static assert  "Unsupported serialization type: InputStream"
../../.dub/packages/vibe-d-0.8.0/vibe-d/data/vibe/data/serialization.d(547,114):        instantiated from here: deserializeValueDeduced!(InputStream)
../../.dub/packages/vibe-d-0.8.0/vibe-d/data/vibe/data/serialization.d(690,47):        instantiated from here: deserializeValue!(InputStream)
../../.dub/packages/vibe-d-0.8.0/vibe-d/data/vibe/data/serialization.d(676,31):        instantiated from here: __lambda2!string
../../.dub/packages/vibe-d-0.8.0/vibe-d/data/vibe/data/serialization.d(547,114):        ... (5 instantiations, -v to show) ...
../../.dub/packages/vibe-d-0.8.0/vibe-d/web/vibe/web/rest.d(99,45):        instantiated from here: jsonMethodHandler!(postDeaf, 1LU, WhiteBlowerAPI)
source/app.d(14,30):        instantiated from here: registerRestInterface!(WhiteBlowerAPI)
dmd failed with exit code 1.

What am i doing wrong? Can be Request Handler use with Rest API?

Regards
holo

Re: HTTPServerRequest constructor is not callable

I find out how to force it to work in issue and with help on IRC channel, but it is looking like some "hack" not "proper" solution. Should we handle POSTs requests in REST API such way? If not what is proper way to post just JSON file to api? Only with parameters?

Re: HTTPServerRequest constructor is not callable

Am 24.08.2017 um 00:07 schrieb holo:

I find out how to force it to work in issue and with help on IRC channel, but it is looking like some "hack" not "proper" solution. Should we handle POSTs requests in REST API such way? If not what is proper way to post just JSON file to api? Only with parameters?

Sending files is currently not yet directly supported by the REST
interface generator, so that accessing the response object directly
using the mentioned "hack" with @before is currently the only way to
make this work in an efficient way.

It's something that is planned to be supported in some way, though.
Maybe using an annotation or using a special return type:

 @sendFile
 NativePath getSomeJsonFile(string name)
 {
     return NativePath("files/"~name~".json);
 }

(Note: this could actually be implemented on top of the current API by
defining @sendFile as an alias to @after)

Another possibility would be to support returning an InputStream that
contains arbitrary contents to be sent as the body.