On Fri, Jul 9, 2010 at 10:27 AM, irum <irumrauf...@gmail.com> wrote: > 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?
are you trying to do the request from Django? to the same server? on the development server? the development server is single-request. it won't answer to a new request until the current one has been completed. if you need to do a request to yourself, use a real server. of course, if you're requesting to yourself, you shouldn't have to go through HTTP, it would far better to directly access the underlying resources. > 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. HATEOAS: http://blogs.sun.com/craigmcc/entry/why_hateoas in short, the server shouldn't bother with policy. you should strive to create your resources so that everything that's allowable is acceptable. in your example: when you POST a new 'payment', you have to refer to the 'booking' and 'room' resources involved. these references should be URLs in the POST data. remember that REST is not CRUD, you have to do fairly extensive validations and sanitizations on POSTed data before accepting it. so, the 'payment' resource should verify that the 'booking' and 'room' URLs referenced by the client actually exist and are in the correct state (i.e. the room isn't paid yet). if anything is wrong with the data, don't write anything and respond with a client error, like 400, 406, 409, 412 or similar (check http://en.wikipedia.org/wiki/List_of_HTTP_status_codes). only answer with a 200 (or better, with a 302 to the new resource) if everything was correctly verified and created. that way, you don't care if the client has just GET the related resources, or if that was a week ago, or if the user copied from a napkin. if the reference is valid, accept it; if it's not, don't. -- Javier -- 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.