RejectedSoftware Forums

Sign up

Path variables in REST service

Perhaps my google skills are failing me, but is there a way to access path variables in a REST service?

shared static this() {
    auto resource = new SequenceResource;
    auto settings = new HTTPServerSettings;
    settings.port = 8080;
    settings.bindAddresses = ["::1", "127.0.0.1"];
    auto router = new URLRouter;
    registerRestInterface!FairService(router, resource);
    listenHTTP(settings, router);
}

interface FairService {
	
    @method(HTTPMethod.GET) @path("hash/:id") string test();
	
}

class SequenceResource : FairService {
	
    string test() {
        // How to get path variable here?!
        return "Test: ";
    }
}

(Btw, it took me a while to figure out that I needed an interface and use the templated form of registration in order to get the "method" and "path" attributes working for a REST service. It could be a bit clearer in the docs.)

Re: Path variables in REST service

Found it:

interface FairService {
	
    @method(HTTPMethod.GET) @path("hash/:id") string test(string _id);
	
}

class SequenceResource : FairService {
	
    string test(string _id) {
        return "Test: " ~ _id;
    }
}

Duh!

Re: Path variables in REST service

I'll improve the documentation there. Both, vibe.web.rest and vibe.web.web are currently much too sparsely documented unfortunately.