Andrew
unread,Jul 7, 2008, 9:46:54 PM7/7/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
Here's the situation:
I'm creating an RESTful internal API as an app in our project. Our
'main' app (we'll call it main) is a client of the API app. Since
we're building the API piece by piece as we use it, the emphasis on
all of this is simple simple simple -- with our eye on eventually
opening up pieces of the API to the public.
The general flow looks like:
request => main app handling => API client => API logic.
Because right now both of the apps live in the same project and are
being served from the same boxes (and the API won't be running on a
separate machine for a while), I figured, hey, why not just fake an
HttpRequest from the main app logic and pass it over to API? That way,
we don't need to worry about exposing the internal URLs, we don't need
to worry about authentication right now, it'll be simple.
Right now the API client I've written takes an HTTP method, path, and
params, uses resolve(path, api.urls) to get the view, and then calls
the view using a fake HttpRequest that I populate myself.
The one problem is that I'm finding it much harder to fake the
HttpRequests than I thought -- namely because the RESTful handlers on
the API side are expecting things like request._get_post_and_files()
to be present.
So, my thoughts:
a) Continue using the lightweight API "client" I've written, but
instead of building a HttpRequest, fake a WSGIRequest instead (with
the _minimum_ data needed)
b) Patch the django test client to deal with PUT and DELETE and use
that as our API client
c) Import the API urls.py into the main urls.py and call the API
methods by generating actual HTTP requests
I'm not crazy about c) since it requires more infrastructure work now.
Any thoughts?