2

Most of the backend stuff is in PHP which handle JSON request and response flow of data from Android app to backend.

I'd like to start writing Python code to handle the extra features I'm going to add in my app. How can I do that? Do I need to install Django or something like it in the backend? Our webhost does show "Python support". I'm guessing just a couple of Python classes and some helper library files would suffice.

But here's where I'm conceptually stuck:

In Android, on the app, in the user's side, suppose I send all my queries to backend with this function:

//Pseudo code on Android app
getServerResponse()
{
url = " ??? ";
jsondata = {somedata[a:b]};
response = sendData_andGetResponse(jsondata); // suppose this function sens json data and expects a server response.
showResults(response);

//Pseudo code on backend - BackendProcessing.py

def processRequest():
    # some processing done here
    response = "some_processed_data"
    return response

My problem is, what and how do I integrate the backend Python code and the client side Android app code to communicate with each other. What should the URL be in my Android code to pass data from user to backend? How do I link them?

Do I need to specially setup some third party Python API to handle calls from the Android app at the backend? Or can I just do it with simple Python functions and classes with HTTP request and responses coming in for a particular URI?

Tony K
  • 61
  • 3
  • 10
  • Your question is not really specific enough to answer in a meaningful way. You can write a Python HTTP server from scratch with simple sockets, as you could with PHP. But it's massively more convenient to use a web framework. Find out what your webhoster supports and go with that. If you need further help update the question! – Christian Aichinger Mar 18 '14 at 15:15
  • @ChristianAichinger Hi, thanks for replying. As I did mention in the question body, the host supports Python. What I want to know is, how to interface by backend Python code with Android. So far, searches on Google ended in Google Endpoints and using Phonegap. I'm not looking for that. – Tony K Mar 18 '14 at 15:38
  • 1
    So how did you do it with PHP? Simply via HTTP traffic, right? You can do just the same thing with Python. You can even use the same Android-side code, the same URL structure, etc. as you had with PHP. How did you get your HTTP requests to PHP, were you using Apache as web server? You can interface Python with Apache as well, take a look at mod_wsgi. Try to be more concrete with your questions, I have no idea at what of those steps your problems lie. – Christian Aichinger Mar 18 '14 at 15:43
  • Actually no the code for PHP side wasn't by me. I'm supposed to write Python backend code and I've no idea how to interface it with Android code. Although your last reply cleared up a few things, so I might start there. – Tony K Mar 18 '14 at 16:01

1 Answers1

3

You can include URL of the backend server in the android code. Define a variable for the URL of your backend server and use Httppost method for communication between backend and frontend. Details here http://developer.android.com/reference/org/apache/http/client/methods/HttpPost.html

You can do it with simple Python functions and classes with HTTP request and responses coming in for a particular URI. A third party Python API is not necessary.

You can also use Python based web frameworks like Django for the backend.

priya
  • 63
  • 7