On Fri, Dec 20, 2013 at 11:45 AM, Mario Osorio <[email protected]> wrote: > I need to work on a django app that will eventually benefit from a RESTful > API so it can be used from any web browser as well a from apps writtens for > iOS and Android. > > Being so new to django development I don't even have any ideas on how to use > a RESTful API, for example, > > Should I begin the development use a RESTful API, or should I add ir when > needed? ( it IS going to be used anyways) > Of course I understand I'm adding another layer of work to the final product > but, can someone please explain how bad deep and how complicated this layer > might be? > I've found a couple of online tutorials and I'll soon be working on them, > but I honestly think there is nothing quite like reading the opinions of > different people as to what the workflow with a RESTful API in django > implies. I think a simple overview of the general workflow will answer most > of the questions I have in mind right now. > > Thanks a lot in advanced!
I'm not an expert, but I just happen to be working on something similar. I already had the URLs set up so that the HTML was being rendered, edited, saved, etc. So, then I wanted to add a RESTful API, mirroring the same URLs. A regular URL looks like: http://localhost:8000/person/764526236 I decided to make the REST API look like: http://localhost:8000/person/764526236/?format=json That was as easy as something like this (person is the view, 764526236 is the handle): try: obj = Person.objects.get(handle=handle) except: raise Http404(_("Requested %s does not exist.") % view) if not check_access(request, context, obj, act): raise Http404(_("Requested %s does not exist.") % view) if "format" in request.GET: if request.GET["format"] == "json": person = db.get_person_from_handle(obj.handle) content = str(person.to_struct()) response = HttpResponse(content, mimetype="application/json") return response The 'if "format"' handles the different formats. Hope that helps (or someone can point us both in a better direction). -Doug > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/cc10edc2-e978-461e-986f-43dd73eea63e%40googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAusYCiW69LsCf%3DAfGYJD4oZPpJziJwAaFKtiU%3DxnDb05nxajA%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.

