Project

General

Profile

REST Parameters in URL

Added by Matt Russell over 7 years ago

Using WServer::addResource, how can I specify a path that will allow parameters?

i.e. /entity/:id/attributes

Right now, if I do server_->addResource(resource, "/entity/");, that route will work, but /entity/2 will return a 404

On the otherhand, if I omit the trailing slash, then /entity/3 works, but I have no way of getting the 3. I've tried url(), internalPath(), generateUrl(), wApp->environment().getParameterMap(), etc. Nothing returns that data.


Replies (2)

RE: REST Parameters in URL - Added by Roel Standaert over 7 years ago

In the handleRequest() method of the resource, you get a const Wt::Http::Request& parameter. If you want to access any extra path info, you'll need to use the pathInfo() method of the request.

RE: REST Parameters in URL - Added by Matt Russell over 7 years ago

It works! Thanks!

    (1-2/2)