This is a very general and open-topic question. So yesterday we decided we would like to create an iOS app based off our website that is currently being built with Django. Now, Django, like RoR, is suppose to be transparent to the UI; it shouldn't care what UI the user is using. (Proper MVC).
If I look at some of our code for example, here is how we add an equipment into our system:
@login_required
def add(request):
r_user = request.user.userprofile
form = EquipmentFormAdd(request.POST or None, c_id=r_user.company_id, error_class=DivErrorList)
if form.is_valid():
equipment = form.save(commit=False)
equipment.company_id = r_user.company_id
equipment.added_by_id = request.user.id
default_file_path = EquipmentPicture.get_default_file_path()
url_bucket = r_user.company.s3_bucket.name + default_file_path
cell = form.cleaned_data['cell']
equipment.cell_order = cell.equipment_set.count() + 1
equipment_picture = EquipmentPicture.objects.create(
file=EquipmentPicture.get_default_file_path(),
slug=EquipmentPicture.get_default_slug(),
bucket_name=r_user.company.s3_bucket.name,
bucket=r_user.company.s3_bucket, added_by=request.user,
company=r_user.company, url_with_bucket=url_bucket)
equipment.picture = equipment_picture
equipment.save()
return redirect('equipment_index')
return render(request, 'equipment/add.html', {'equipment_form': form, 'company_id': r_user.company_id})
If I look at this, I see that we are rendering straight-away a template and passing it data. This would't work in iOS.
Few questions:
I see a lot of people creating REST APIs. I don't really see the point of doing that if we can just create HTTPResponses with Django. If we were to use something like TastyPie, we wouldn't be able to just create an equipment (like we do right now) with a POST Statement as if you look at our current add function a lot of stuff is done within that function and TastyPie wouldn't be able to call that.
My main question is should we have a REST API running as well as the normal Django server for both the Web and iOS platform, or just have the same functions, with different entry points and renderings according to it?
When do you create a REST API? A lot of our functions when creating and getting data wouldn't work right now with just standard POST and GET calls. Is that bad?
I am kind of confused... sorry for the long question and thanks again!