0

First of all, I'm not experienced with servers. I just want to know what I have to study to make this happen. But better explanation is well received.

Like said in the Title, how can I do that?

What I want:

Swift iOS app(client-side) JSON -> server -> execute python with provided data

and a return:

Swift iOS app(client-side) JSON <- server <- return of executed python with provided data

I've read about Apache but it involves php(my nightmare) and a lot of more things (like php running python by commands on terminal). Is this the way?

Can I make a server that receives JSON and directly use python to decode, process the data, create a new JSON (an answer) and send back to client?

Can I get away from php?

What technologies (like server, languages, frameworks) do I have to use on this project?

Plus: What's the best choice for database(and the framwork to access it) for small projects? (like a simple app)

Thanks in advance!

denisb411
  • 581
  • 1
  • 7
  • 25
  • The following page should give you an initial overview: https://wiki.python.org/moin/WebFrameworks – dthulke Apr 07 '17 at 16:44

1 Answers1

1

This shouldn't be too difficult. If I were you I'd ignore the iOS / Swift side at first and just get yourself a web service up and running. See http://www.dreamsyssoft.com/python-scripting-tutorial/create-simple-rest-web-service-with-python.php This seems like a nice tutorial for a simple REST app.

For small projects, I've used sqlite and been pretty happy with it. It's relatively simple and works as advertised: https://www.tutorialspoint.com/sqlite/sqlite_python.htm

As part of your iOS / client side, include the python code that you want executed in the payload of the request. Then inside your REST app, you can execute the python code for a result, store it in a JSON object and return it to the client.

This should all be achievable within python and no need for php or anything. See this post for executing python code from python: How do I execute a string containing Python code in Python?

Good luck

Community
  • 1
  • 1
DDoomUs
  • 183
  • 9
  • Thanks for answer. In your example, I need to call the python script I want to execute right after 'opening' the received JSON by using exec or eval functions? Sorry for the very lay question. – denisb411 Apr 07 '17 at 18:45
  • @DenisCandido right. I think "eval" is probably more what you're looking for, in the last link I provided, look at the accepted answer from hekevintran on how to get the result of the code you executed. Edit: And yes, where you "handle" requests in your server code you'll (step 1) get the data / code / payload from the request (step 2) execute it using eval (step 3) get the result and stuff it in a response (step 4) send the response along, back to the client – DDoomUs Apr 08 '17 at 22:44
  • I went with Django. Already learning. But thanks for the answer. – denisb411 Apr 08 '17 at 23:15