Skip to main content

Ionic app with a Django backend: Part 1 - The backend

In this post, I will be talking about my latest Github repository(repo); IonicAppWithRestBackend and delve into details about what it is and the problem it aims to solve.

Introduction

The idea of this repo is to provide code samples for both the backend and front-end for an Ionic app that communicates with a RESTful backend. The aim is to bring many disparate aspects of building a solution like this(hybrid app that talks to a REST backend) and to be able to see most of them as one complete solution. Also, a solution such as this ensures you can test your Ionic app locally during development. Still not clear? read on to find out what I mean.

Note: Once I started writing this post, I realised that it would be a really long blog post, so I decided to split it into individual parts in hopes that it's an easier read. In part 1, I will be talking about what the backend solution is and how to get it running.

Motivation

In 2014, I started working on a project with someone which involved building a mobile app that fetches/sends data to a REST backend. My associate did not have a very technical background...I mean she knew a lot more than people from her academic background would but she wasn't a programmer. Therefore I wanted to  build a solution which would involve us having fewer meetings, during the development stage. I wanted a solution such that she can run a REST based backend on a server on her machine, then run the app using Ionic serve and test the app. 

In my quest to build something like this, I managed to find a solution to all my problems. However a solution like this is composed of several disparate(different) components as a result of which the I needed was scattered across a bunch of different places. Once I found all the information I needed to build this solution, I thought to myself "hmm...it would have helped me if all of it was in one place"....and that is the story of how I thought about creating this repo and sharing this solution.

In case you are wondering what happened to that project I was working on with my associate... well after working on it for a year it came to a very abrupt and a sudden end! I will talk a bit about that later but for now, I will talk about the solution(code) in this repo.

Solution

Let's start by examining the structure of this repo
  • IonicAppWithRestBackend
    • Backend: A folder that can store backend solutions
      • Python/Django: I thought about starting simple with a Django backend
    • IonicApp: This has the Ionic app that you can run in your browser

More details on the backend

There are many ways in which we can build a backend i.e. Java, Nodejs, PHP, Rails etc. I started off by building a RESTful backend with Java(using Jersey) only to realise that it would require a comparatively more complicated setup to get it running. I love Java, there's no two ways about it, but the aim of this repo was to keep it such that someone can just check it out and get it running with minimal setup. As a reader at this point, you maybe thinking, 

Ok great, so how do I run the backend solution?

The backend has been written using Python/Django and should you want to know more about Django, you can read it here or if you want to know how to write Django web apps, read the excellent tutorial series Writing your first Django app series. Ok, now to run the backend, 

Clone the repo
git clone https://github.com/cptdanko/IonicAppWithRestBackend
Navigate to the backend project directory
cd IonicAppWithRestBackend/backend/python_django/restBackend/
Note: if you are using Windows, you may want to change "/" to "\" in the above command.

Once there you can run the backend server with the following command
python manage.py runserver
Once you execute that command, expect to see something like this



Great! The backend solution is now running at localhost. In case you are wondering about the Web server that is running our backend solution? Django comes with a lightweight Web server written purely in Python, if you want to know more about it, you can read more about it here.

This is a very simple REST backend which exposes a Django application titled abstractApp which has only 2 REST endpoints that return some data as JSON.

Conclusion and part 2

So that concludes part 1 and should you have any questions? please leave a comment or if you think you can improve this repo, then fork the repo and create a pull request or if you have any problems then create an issue on Github. This post continues in part 2 and you can read it here.


Lastly, I am working on my startup full-time right now, so if you find my blogposts useful and want to see me share more useful stuff in the future, please do support me. You can support me, 

Whichever version you try please leave us an app store review from you would be helpful. 


Comments

I read over your blog, and I found it inquisitive. Also, you may also find Django Development Company Interested.

Popular posts from this blog

Upload to AWS S3 from Java API

In this post, you will see code samples for how to upload a file to AWS S3 bucket from a Java Spring Boot app. The code you will see here is from one of my open-source repositories on Github, called document-sharing. Problem Let’s say you are building a document sharing app where you allow your users to upload the file to a public cloud solution. Now, let’s say you are building the API for your app with Spring Boot and you are using AWS S3 as your public cloud solution. How would you do that? This blog post contains the code that can help you achieve that. Read more below,  Upload to AWS S3 bucket from Java Spring Boot app - My Day To-Do (mydaytodo.com)

Addressing app review rejections for auto-renewing subscription in-app purchase (iOS)

The ability to know what the weather is like while planning your day is a feature of  My Day To-Do  Pro and as of the last update it’s also a part of the  Lite version . Unlike the Pro version it’s an auto-renewing subscription based  in-app purchase (IAP)  in the Lite version. What means is that when a user purchases it, the user only pays for the subscription duration after which the user will be automatically charged for the next period. Adding an  auto-renewing  subscription based IAP proved to be somewhat challenging in terms of the app store review i.e. the app update was rejected by the App Review team thrice because of missing information about the IAP. Therefore in this post I will share my experiences and knowledge of adding auto-renewing IAP in hopes to save someone else the time that I had to spend on this problem. In-App purchase This year I started adding IAPs to My Day To-Do Lite which lead to learning about different types of IAP...

Getting started with iOS programming using Swift (Part 1)

I have not been too fond of Objective-C, which was the primary reason for me to stay away from making iOS apps till now. So what changed? Well Apple has done something very interesting recently and that is the introduction of a new programming language i.e. Swift. Swift is awesome, it almost feels like Python, C++ and Objective-C had a baby with some of their good parts in them. So I have been getting to know Swift and it is an awesome language to program in. What I am going to share with this and a series of blog posts are solutions to some problems that i have encounter while i am trying to finish my first iOS app. The one hurdle that I have encountered while getting started on developing an iOS app is that a majority of the solutions for iOS specific problems provide solutions to them using Objective-C. Which is fair, because Swift has not been around for that long. Anyway let us get started with a few basics, A few basics I would highly recommend having a read of this book...