Hi,
I am relatively new to working with django and web services. I am
using django-piston and I posted this on that group as well but got no
reply yet. Posting it here since its more active community and my
problem is not related to Django-piston in particular but rather
Django and web services in general. Hoping to get a reply from here:)

I am trying to implement a small
example of a RESTful web service i.e a hotel booking service. I have
implemented my resources successfully with read, update and delete
methods according to my specifications. I can invoke them successfully
using 'curl' and get the desired status codes. The problem now I am
stuck in implementing full behavior of my service that invokes a
particular resource after performing a certain method on a resource.
For example, after invoking successfully a POST method on 'booking'
resource, I want to invoke a POST on 'payment' resource.

My main problem is :
- where do I implement all the specifications for my RESTful web
service that invokes methods on these resources in a specific sequence
as desired. Is it in the 'view.py' file that I create in the 'api'
folder? Can someone give me any example on how to write web service
clients in django / django-piston? I googled but found no good result.

- Secondly, my main problem is how do I invoke these methods with in
my code? I have tried urllib/ urllib2. When I invoke a remote address
like 'http://www.example.com', it returns the html file but when I
invoke local host, i.e. http://127.0.0.1:8000/api/hb/bookings/21/ ,
curl does not respond when I invoke that handler from curl on command
prompt. My code is like this:

class RoomHandler(BaseHandler):
   allowed_methods = ('GET', 'PUT', 'POST', 'DELETE')
   model = room
   fields = ('rType', 'floor')

   def read(self, request, id=0):
.....
 if b:
              b = booking.objects.get(id=id)
              response = room.objects.filter(id = b.room_id)
              req = urllib2.Request('http://127.0.0.1:8000/api/hb/
bookings/21/')
          #    req = urllib2.Request('http://www.example.com')
              response = urllib2.urlopen(req)
              the_page = response.read()
              type(the_page)
              return the_page

>From command prompt, I invoke. curl 
>http://127.0.0.1:8000/api/hb/bookings/21/rooms/
It does not respond anything, even if left for long time. However if I
use remote url, i.e. :
req = urllib2.Request('http://www.example.com') , it returns the html
file. Where am I going wrong?

Thirdly, how do I implement conditions in my client to invoke a
certain method of a resource, i.e. before invoking POST on a 'payment'
resource, I want to perform a GET on 'booking' and 'room' resource,
only if I get response code of 200 (i.e. booking and room resource is
created), I should be able to invoke POST on 'payment' resource else
it should set a flag to false.  I will be implementing an algorithm,
but I was thinking can we put conditions on invoking methods of
resource like we would do with JML for java interfaces?

I have been stuck with these problems for almost two weeks, googling
and trying different things but I am still stuck. Hoping to hear
something from here.

Thankyou for your time and looking forward,
Irum

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to