I have a django web app created already, with a simple user table (username/password). I also have an iOS app (swift) set up, and was wondering what would be the best way to go about coding the login system?
From what I have gathered from research - I will have to make REST calls to an API created from the existing django app. Would it be better to use TastyPie or Django Rest Framework for this?
Are there specific things I have to keep in mind when doing the API for the django app? Also, what would be the url that i use for the rest calls, would it be the existing server that the django web app is on?
My qualifications for this answer come from 3 months of work on an identical system to the one you described. Your question holds many parts, so I will begin with the server.
Correct, your clients (app, web, or otherwise) should communicate with your server through an API.
Hopefully your "simple user table" uses the default Django user model, as 3rd party security frameworks are going to make your life much simpler when protecting an open API. Although it depends on your security needs, I recommend the Django OAuth Toolkit for its OAuth2 support, password reset workflow, and prebuilt URL endpoints for common authentication interactions. Even better, this library natively supports the Django Rest Framework.
I do not have experience with TastyPie, however I can vouch for DRF. The generic views matched our major API design points well, and DRF's similarities to the Django Form API means our custom dashboard has a wonderful symmetry to the API. I recommend you first map out the major components of your API, then research both frameworks to learn which will fit your project best.
(Bonus Tip: If this is your first time designing a REST API, flip through a copy of Build APIs You Won't Hate)
Common practice is to host your API URLs on a subdomain, followed by a version path, such as
api.example.com/v1/
. The subdomain separates your URLs from core web pages and denotes these endpoints are specifically for your API. The version path is a good practice to support legacy APIs as you upgrade.Security is a big one. Depending on your API, there could be some sensitive parts of your application exposed to the public. Write tests to ensure you are not poking new holes in your security, and leave OAuth to the pros. Other than that, make sure your server is ready to handle your traffic, and spend plenty of time perfecting your model.
When coding client-side, always use best practices to retrieve and store credentials. Communicate with your server over SSL, store only what you need, and destroy the expected data when a user logs out. Remember, if your app stores usernames and passwords, it stores sensitive data (because people have a funny tendency to reuse passwords for important things). Finally, clearly communicate the login process to your users with helpful error messages and loading animations. As you can see by now, the login process is fairly complex, but if executed well it will feel effortless.
Login Form
Register Form
class RegisterViewController: UIViewController, UITextFieldDelegate, UITextViewDelegate {
//MARK:- Same & re-Password