You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Henrik S <he...@tomatoservers.com> on 2022/04/21 03:21:48 UTC

path recognition question

given the sample url:

/api/user/id

the part of "/api/user" is fixed.  and there is a handler setup for this 
path.

how to get the id part in mod_perl?

in other framework I could get it with the similar format:

/api/user/:id

puts "hallo #{id}"


Thank you.

Re: path recognition question

Posted by Mithun Bhattacharya <mi...@gmail.com>.
You still have $r->path just pull the id from it ?

On Thu, May 5, 2022, 4:20 PM Michael A. Capone <mc...@cablewholesale.com>
wrote:

> (Sorry for the late reply, been out of town)
>
> Recognizing that I've never gone as indepth with mod_perl as other users,
> but it seems to me that accessing "id" here would just be a matter of
> grabbing the PATH_INFO environment variable, wouldn't it?
>
> if the url is www.example.com/app/user/12345, then the program is
> /app/user, and $ENV{'PATH_INFO'} would contain /12345.  Chop off the
> leading forward slash and you've got your ID.
>
> Note that you'd have to have PerlSetupEnv on (the default, although I
> think many may turn it off).
>
> Or am I completely missing something?
>
> Michael
>
> On 4/21/22 6:40 AM, John Dunlap wrote:
>
> I ended up writing something custom to do that.
>
> On Wed, Apr 20, 2022 at 11:22 PM Henrik S <he...@tomatoservers.com>
> wrote:
>
>> given the sample url:
>>
>> /api/user/id
>>
>> the part of "/api/user" is fixed.  and there is a handler setup for this
>> path.
>>
>> how to get the id part in mod_perl?
>>
>> in other framework I could get it with the similar format:
>>
>> /api/user/:id
>>
>> puts "hallo #{id}"
>>
>>
>> Thank you.
>>
>
>
> --
> John Dunlap
> *CTO | Lariat *
>
> *Direct:*
> *john@lariat.co <jo...@lariat.co>*
>
> * Customer Service:*
> 877.268.6667
> support@lariat.co
>
>
>

Re: path recognition question

Posted by "Michael A. Capone" <mc...@cablewholesale.com>.
(Sorry for the late reply, been out of town)

Recognizing that I've never gone as indepth with mod_perl as other 
users, but it seems to me that accessing "id" here would just be a 
matter of grabbing the PATH_INFO environment variable, wouldn't it?

if the url is www.example.com/app/user/12345, then the program is 
/app/user, and $ENV{'PATH_INFO'} would contain /12345.  Chop off the 
leading forward slash and you've got your ID.

Note that you'd have to have PerlSetupEnv on (the default, although I 
think many may turn it off).

Or am I completely missing something?

Michael

On 4/21/22 6:40 AM, John Dunlap wrote:
> I ended up writing something custom to do that.
>
> On Wed, Apr 20, 2022 at 11:22 PM Henrik S <henrik@tomatoservers.com 
> <ma...@tomatoservers.com>> wrote:
>
>     given the sample url:
>
>     /api/user/id
>
>     the part of "/api/user" is fixed.  and there is a handler setup
>     for this
>     path.
>
>     how to get the id part in mod_perl?
>
>     in other framework I could get it with the similar format:
>
>     /api/user/:id
>
>     puts "hallo #{id}"
>
>
>     Thank you.
>
>
>
> -- 
> John Dunlap
> /CTO | Lariat/
> /
> /
> /*Direct:*/
> /john@lariat.co <ma...@lariat.co>/
> /
> *Customer Service:*/
> 877.268.6667
> support@lariat.co <ma...@lariat.co>


Re: path recognition question

Posted by Jacques Deguest <ja...@deguest.jp>.
If you are looking to build a REST api with Apache mod_perl, you might 
be interested in Net::API::REST (https://metacpan.org/pod/Net::API::REST)

Jacques

On 2022/04/21 23:27, John Dunlap wrote:
> I sent this 8 years ago but, at the time, no one was interested.
> image.png
>
>
> On Thu, Apr 21, 2022 at 9:40 AM John Dunlap <Jo...@lariat.co> wrote:
>
>     I ended up writing something custom to do that.
>
>     On Wed, Apr 20, 2022 at 11:22 PM Henrik S
>     <he...@tomatoservers.com> wrote:
>
>         given the sample url:
>
>         /api/user/id
>
>         the part of "/api/user" is fixed.  and there is a handler
>         setup for this
>         path.
>
>         how to get the id part in mod_perl?
>
>         in other framework I could get it with the similar format:
>
>         /api/user/:id
>
>         puts "hallo #{id}"
>
>
>         Thank you.
>
>
>
>     -- 
>     John Dunlap
>     /CTO | Lariat/
>     /
>     /
>     /*Direct:*/
>     /john@lariat.co/
>     /
>     *Customer Service:*/
>     877.268.6667
>     support@lariat.co
>
>
>
> -- 
> John Dunlap
> /CTO | Lariat/
> /
> /
> /*Direct:*/
> /john@lariat.co/
> /
> *Customer Service:*/
> 877.268.6667
> support@lariat.co


Re: path recognition question

Posted by John Dunlap <Jo...@lariat.co>.
I sent this 8 years ago but, at the time, no one was interested.
[image: image.png]


On Thu, Apr 21, 2022 at 9:40 AM John Dunlap <Jo...@lariat.co> wrote:

> I ended up writing something custom to do that.
>
> On Wed, Apr 20, 2022 at 11:22 PM Henrik S <he...@tomatoservers.com>
> wrote:
>
>> given the sample url:
>>
>> /api/user/id
>>
>> the part of "/api/user" is fixed.  and there is a handler setup for this
>> path.
>>
>> how to get the id part in mod_perl?
>>
>> in other framework I could get it with the similar format:
>>
>> /api/user/:id
>>
>> puts "hallo #{id}"
>>
>>
>> Thank you.
>>
>
>
> --
> John Dunlap
> *CTO | Lariat *
>
> *Direct:*
> *john@lariat.co <jo...@lariat.co>*
>
> *Customer Service:*
> 877.268.6667
> support@lariat.co
>


-- 
John Dunlap
*CTO | Lariat *

*Direct:*
*john@lariat.co <jo...@lariat.co>*

*Customer Service:*
877.268.6667
support@lariat.co

Re: path recognition question

Posted by John Dunlap <Jo...@lariat.co>.
I ended up writing something custom to do that.

On Wed, Apr 20, 2022 at 11:22 PM Henrik S <he...@tomatoservers.com> wrote:

> given the sample url:
>
> /api/user/id
>
> the part of "/api/user" is fixed.  and there is a handler setup for this
> path.
>
> how to get the id part in mod_perl?
>
> in other framework I could get it with the similar format:
>
> /api/user/:id
>
> puts "hallo #{id}"
>
>
> Thank you.
>


-- 
John Dunlap
*CTO | Lariat *

*Direct:*
*john@lariat.co <jo...@lariat.co>*

*Customer Service:*
877.268.6667
support@lariat.co

Re: path recognition question

Posted by Jacques Deguest <ja...@deguest.jp>.
I would use path_info.
See Apache2::RequestRec manual page.

Regards,
Jacques

On 2022/04/21 12:21, Henrik S wrote:
> given the sample url:
>
> /api/user/id
>
> the part of "/api/user" is fixed.  and there is a handler setup for 
> this path.
>
> how to get the id part in mod_perl?
>
> in other framework I could get it with the similar format:
>
> /api/user/:id
>
> puts "hallo #{id}"
>
>
> Thank you.