Am Dienstag 19 August 2008 11:48:06 schrieb Tim Hawkins:
> Im having a couple of small issues whilst attempting to add the
> ability to handle  REST based api calls with Json
>
> Im trying to create an action controller that will handle:
>
> mapping
>
>   /api/v1/test/......                                 =>  json_test
>   /api/v1/test/test1/......                   =>  json_test.test1
>   /api/v1/test/test2/.....                    =>  json_test.test2
>
> My UrlMaps are:
>
>
>               // Add the API routes
>
>       1.      favcoreApp.mapUrl("^/api/v1/test/(.*)$", "json_test");
>       2.      favcoreApp.mapUrl("^/api/v1/test/test1/(.*)$", 
> "json_test.test1");
>       3.      favcoreApp.mapUrl("^/api/v1/test/test2/(.*)$", 
> "json_test.test2");
>
> Problem 1. The definition for the "json_test" mapping call (1) masks
> all the other calls, but that may be related to problem 2.
>
> Problem 2. I cant access the sub-components json_test.test1 or
> json_test.test2 , they don't seem to be registering and I cant see why
> not. The main component seems to be registering fine.
>
> Problem 3. I would like to parse the unmatched part of the URL ($1) to
> the component so it can further decode the request and act on it. is
> there an easy way of doing that, I can easily fish the whole request
> out of the RequestObject, but I would have to remove the prefix, and
> that requires the prefix to be set-up in two places, in the URLMap and
> in the component, which is not very cool.
>
try this one:
        favcoreApp.mapUrl("^/api/v1/test/([^/]*)$", "json_test")
                .setPathInfo("$1");
        favcoreApp.mapUrl("^/api/v1/test/test1/(.*)$", "json_test.test1")
                .setPathInfo("$1");
        favcoreApp.mapUrl("^/api/v1/test/test2/(.*)$", "json_test.test2")
                .setPathInfo("$1");

"([^/]*)" match 0 or more characters, which are not '/', so a 
url "/api/v1/test/test1/something" won't match any more. This would solve 
problems 1 and 2.

The method mapUrl returns a reference to a tnt::Maptarget, which has a 
method "setPathInfo". Setting it to "$1" let you access the first bracketed 
expression in your component with "request.getPathInfo()", which returns the 
passed parameter as a std::string. Without "setPathInfo" you get the full 
url.

...
>
> Im also curious about this line in the class
>    _component_json_test(const tnt::Compident& ci, const
> tnt::Urlmapper& um, tnt::Comploader& cl);
>
> any explanations about what it does?
>
This is the definition of the constuctor of your component class.

I just saw, that I should add doxygen comments to the classes, so you can find 
them in the documentation.


Tommi

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general

Reply via email to