Search code examples
haxe

Sub-Route Remote Call with Tink Web


I defined a sub-route and i want to call it from my JsClient.

I tried to follow the Quick Start instructions but sub-route call isn't documented.

class App {

    public static function main() {
        var remote = new Remote<ApiRoute>(new JsClient(), new RemoteEndpoint(new Host("localhost",8080)));
        remote.api.upload().handle(function(o) switch o {
            case Success(result): trace(result);
            case Failure(e): trace(e);
        });
    }

}

class ApiRoute {
    public function new() { }

    @:sub public var api = new Api();
}

class Api {

    public function new() { }

    @:post('/upload')
    public function upload(){
        return '';
    }

}

The compiler doesn't like it : Void -> tink.web.proxy.Remote1 has no field upload


Solution

  • It is not about sub routes. But vars/props are converted to function call in proxies. So you should write remote.api().upload()