I've been playing around with web.py and mimerender to create a little
webservice that will query other devices and respond via html/json/
xml.
What I want to do is have the url in the format of.
/identifier/function/arg1
or
/function/identifier/arg1
i've noticed get can return the url(?) via name. So this works great
for single arguments, but how would I extend this to multiple ones?.
Splitting on / seems like it would be a bad idea, and there is
probably a better way I'm overlooking.
On Sun, Mar 25, 2012 at 9:51 PM, Beau <beautr...@gmail.com> wrote: > Hello,
> I've been playing around with web.py and mimerender to create a little > webservice that will query other devices and respond via html/json/ > xml.
> What I want to do is have the url in the format of.
> /identifier/function/arg1
> or
> /function/identifier/arg1
> i've noticed get can return the url(?) via name. So this works great > for single arguments, but how would I extend this to multiple ones?. > Splitting on / seems like it would be a bad idea, and there is > probably a better way I'm overlooking.
> -- > You received this message because you are subscribed to the Google Groups > "web.py" group. > To post to this group, send email to webpy@googlegroups.com. > To unsubscribe from this group, send email to > webpy+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/webpy?hl=en.
> You should just be able to handle this with a regex in the url definitions.
> urls = ('/(.*?)/(.*?)/(.*?)', 'handler')
> class handler:
> def GET(self, identifier, function, arg):
> I wouldn't be surprised if there is a better way to do this though...
> On Sun, Mar 25, 2012 at 9:51 PM, Beau <beautr...@gmail.com> wrote:
> > Hello,
> > I've been playing around with web.py and mimerender to create a little
> > webservice that will query other devices and respond via html/json/
> > xml.
> > What I want to do is have the url in the format of.
> > /identifier/function/arg1
> > or
> > /function/identifier/arg1
> > i've noticed get can return the url(?) via name. So this works great
> > for single arguments, but how would I extend this to multiple ones?.
> > Splitting on / seems like it would be a bad idea, and there is
> > probably a better way I'm overlooking.
> > --
> > You received this message because you are subscribed to the Google Groups
> > "web.py" group.
> > To post to this group, send email to webpy@googlegroups.com.
> > To unsubscribe from this group, send email to
> > webpy+unsubscribe@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/webpy?hl=en.
But what about when the second and third parameters are not necessary?
Which means following urls need to be matched:
* /function
* /function/identifier
* /function/identifier/arg1
> You should just be able to handle this with a regex in the url > definitions.
> urls = ('/(.*?)/(.*?)/(.*?)', 'handler')
> class handler:
> def GET(self, identifier, function, arg):
> I wouldn't be surprised if there is a better way to do this though...
> On Sun, Mar 25, 2012 at 9:51 PM, Beau <beautr...@gmail.com> wrote:
>> Hello,
>> I've been playing around with web.py and mimerender to create a little
>> webservice that will query other devices and respond via html/json/
>> xml.
>> What I want to do is have the url in the format of.
>> /identifier/function/arg1
>> or
>> /function/identifier/arg1
>> i've noticed get can return the url(?) via name. So this works great
>> for single arguments, but how would I extend this to multiple ones?.
>> Splitting on / seems like it would be a bad idea, and there is
>> probably a better way I'm overlooking.
>> --
>> You received this message because you are subscribed to the Google Groups >> "web.py" group.
>> To post to this group, send email to webpy@googlegroups.com.
>> To unsubscribe from this group, send email to >> webpy+unsubscribe@googlegroups.com.
>> For more options, visit this group at >> http://groups.google.com/group/webpy?hl=en.
This way, anything that hits /uiMethods/foo is a web method call, and
I can still do normal mappings for static pages, templates, etc.
I then use the following handler for GET and POST, which in turn call
the function by *name*
class uiMethods:
def GET(self, method):
try:
methodToCall = getattr(self, method)
result = methodToCall()
return result
except Exception as ex:
raise ex
def POST(self, method):
try:
methodToCall = getattr(self, method)
result = methodToCall()
return result
except Exception as ex:
raise ex
def hello(self):
print "hello"
So, localhost:8080/uiMethods/hello will now map to your function, and
you can add new functions all day long without messing around with
more url mappings.
On Mar 25, 11:51 pm, Beau <beautr...@gmail.com> wrote:
> I've been playing around with web.py and mimerender to create a little
> webservice that will query other devices and respond via html/json/
> xml.
> What I want to do is have the url in the format of.
> /identifier/function/arg1
> or
> /function/identifier/arg1
> i've noticed get can return the url(?) via name. So this works great
> for single arguments, but how would I extend this to multiple ones?.
> Splitting on / seems like it would be a bad idea, and there is
> probably a better way I'm overlooking.
On Sun, Apr 8, 2012 at 10:02 PM, 罗晟 <sheng.peisi....@gmail.com> wrote: > Inspired me! Thanks.
> But what about when the second and third parameters are not necessary? > Which means following urls need to be matched: > * /function > * /function/identifier > * /function/identifier/arg1
> This puzzled me for quite a long time...
> 在 2012年3月27日星期二UTC+8上午2时24分18秒,PhantomXC写道:
>> You should just be able to handle this with a regex in the url >> definitions.
>> urls = ('/(.*?)/(.*?)/(.*?)', 'handler')
>> class handler:
>> def GET(self, identifier, function, arg):
>> I wouldn't be surprised if there is a better way to do this though...
>> On Sun, Mar 25, 2012 at 9:51 PM, Beau <beautr...@gmail.com> wrote:
>>> Hello,
>>> I've been playing around with web.py and mimerender to create a little >>> webservice that will query other devices and respond via html/json/ >>> xml.
>>> What I want to do is have the url in the format of.
>>> /identifier/function/arg1
>>> or
>>> /function/identifier/arg1
>>> i've noticed get can return the url(?) via name. So this works great >>> for single arguments, but how would I extend this to multiple ones?. >>> Splitting on / seems like it would be a bad idea, and there is >>> probably a better way I'm overlooking.
>>> -- >>> You received this message because you are subscribed to the Google >>> Groups "web.py" group. >>> To post to this group, send email to webpy@googlegroups.com. >>> To unsubscribe from this group, send email to webpy+unsubscribe@** >>> googlegroups.com <webpy%2Bunsubscribe@googlegroups.com>. >>> For more options, visit this group at http://groups.google.com/** >>> group/webpy?hl=en <http://groups.google.com/group/webpy?hl=en>.
> To post to this group, send email to webpy@googlegroups.com. > To unsubscribe from this group, send email to > webpy+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/webpy?hl=en.