Hi people!
I've just searched some time for a way to acomplish something, that seems to be missing from Django or where there doesn't seem to be a Django app for that. Or maybe I just don't get it.
I have created an app, that has a model and uses CBVs and templates to display a nice Web UI (say hello,
SKD).
Now, I'd like to add a restful API to my app. Basically, I'd like the API to do exactly the same things the Web UI does. I even would like to reuse my existing URLs for that! I explicitly don't want to create shadow views for something like Tastypie or something.
I'm thinking of a way of identifying API-requests (for example, simply adding a "?json"-Parameter) and reacting to this requests.
For example:
I have a view called UserListView, which reacts to the url "(...)/users/list", is based on a slightly modified version of ListView and displays a nice Web UI listing all users in the system. If I call the URL like "(...)/users/list?json" I would like to use the exact class, but want to return JSON code returning the same data. (I'm speaking DRY here)
Another example:
Another view's called UserCreateView, that returns a form when the user GETs the URL "(...)/users/create" and ultimatively creates the user when he POSTs to the URL. Same thing here: When GETting the URL with some magic JSON parameter, I'd like to get JSON code, that describes the needed fields (although this functionality would be optional). When I POST to it with the JSON-parameter, it would accept JSON input, create the user and return some status, also in JSON-form.
Oh, and by the way, I would also like to have my authentication and authorization-checks to work well with the API.
The existing frameworks (like the mentioned Tastypie) only helps creating REST APIs beside the actual code used for WEB-UIs, not reusing it and thus doesn't comply to the DRY-principle in my eyes.
Does somebody know of a library or application, that does what I want or am I getting something wrong here?
Thanks.