GET queries other than ID

50 views
Skip to first unread message

David Shavers

unread,
Apr 21, 2017, 3:12:00 PM4/21/17
to web2py-users
Hi,

How do I GET data by using the "cost-per-night" url? ID works fine, but that's the only thing that does.


www.example.com/app/default/api/patterns gives me this:

/room_owner[room_owner]
/room-owner/id/{room_owner.id}
/room-owner/id/{room_owner.id}/:field
/room-owner/cost-per-night/{room_owner.cost_per_night.ge}/{room_owner.cost_per_night.lt}
/room-owner/cost-per-night/{room_owner.cost_per_night.ge}/{room_owner.cost_per_night.lt}/:field


Desired result -
www.example.com/app/default/api/room_owner

Desired result -
www.example.com/app/default/api/room-owner/id/1.json

NOT Desired -
www.example.com/app/default/api/room-owner/cost-per-night/25.json

How do I make the last query work?

David Shavers

unread,
Apr 24, 2017, 10:50:59 AM4/24/17
to web2py-users
Bump

Anthony

unread,
Apr 24, 2017, 3:07:56 PM4/24/17
to web2py-users
On Friday, April 21, 2017 at 3:12:00 PM UTC-4, David Shavers wrote:

/room-owner/cost-per-night/{room_owner.cost_per_night.ge}/{room_owner.cost_per_night.lt}
/room-owner/cost-per-night/{room_owner.cost_per_night.ge}/{room_owner.cost_per_night.lt}/:field


Notice the pattern for cost-per-night (which presumably is a float or decimal field) includes placeholders for the lower and upper bounds of a range -- so the url must be something like /room-owner/cost-per-night/25/30.json.

If you want to specify an exact cost and test for equality, you can create your own pattern instead of using the auto-generated patterns:

/room-owner/cost-per-night/{room_owner.cost_per_night.eq}

Anthony

David Shavers

unread,
Apr 24, 2017, 3:15:48 PM4/24/17
to web2py-users
Hey Anthony,

Thanks for replying. So what you're saying is that the auto generated value for cost_per_night is trying to get me to put in two integers and that the resulting json will be a range withing those two? For example: the link you posted would give me all of the values between 25 and 30?

Anthony

unread,
Apr 24, 2017, 3:19:37 PM4/24/17
to web2py-users
On Monday, April 24, 2017 at 3:15:48 PM UTC-4, David Shavers wrote:
Hey Anthony,

Thanks for replying. So what you're saying is that the auto generated value for cost_per_night is trying to get me to put in two integers and that the resulting json will be a range withing those two? For example: the link you posted would give me all of the values between 25 and 30?


Yes, that is the default set of patterns for numeric fields.

Anthony

David Shavers

unread,
Apr 24, 2017, 3:24:19 PM4/24/17
to web2py-users
Sweet, thanks!

David Shavers

unread,
Apr 30, 2017, 1:03:24 PM4/30/17
to web2py-users

Hey, Anthony

here is the finished product of what i was working on. It's an android app that lets you rent out your property to strangers. The payments and database are handled by web2py.


Also, how do i do POST methods? I'm looking at the web2py slice now, but that's one of the only example i can find 
Reply all
Reply to author
Forward
0 new messages