I've been assigned to create an RESTful Android application for an existing web service which is built using Django.
My current design idea is to have the Android application receive a JSON version of the data that would normally be sent to the Django template on each url. So my view would look like:
#The site stores and organizes user's medical experiences by allowing search of
# what treatments have been effective for a particular condition
treatment_for_condition = {'treatment' : treatment, 'condition' : condition}
if send_as_json :
return HttpResponse(json.dumps(treatment_for_condition),mimetype='application/json')
else:
t = loader.get_template('results.html')
return HttpResponse(t.render(treatment_for_condition))
Is there an elegant way to set the "send_as_json" variable? I'm considering the two following strategies:
1) Adding a qualifier to the end of all URLs so that /condition/treatment/ will return a webpage and /condition/treatment/?json=true will return a JSON object
2) Creating a subdomain json.treatmentreport.com that will set the "send_as_json" variable to true, then dispatch to the same view as if it were in the www domain.
Can either of these solutions be implemented elegantly? Or am I going about this completely the wrong way?