How can I respond to requests with Python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

How can I respond to requests with Python?

I want to create a backend app in Python. Should I use a third-party library? How does the code looks like?

4th Jul 2017, 11:15 PM
Eduardo Silva
Eduardo Silva - avatar
8 Answers
+ 17
""" If the question was about how to handle web server with Python (instead of common Php), yes you need 'third party' module/framework such as Django, Flask or Bottle... The code will look like: """ from bottle import route, run @route('/hello') def hello(): return "Hello World!" run(host='localhost', port=8080, debug=True) # Bottle basic code for handle response to web request: other frameworks would use same principle of decorators function ^^
5th Jul 2017, 1:53 AM
visph
visph - avatar
+ 11
Yes: the code example provided is very basic and use a fixed url route, but you can build very complex 'filter', getting parameters inside and so on: all the stuff to build a complete web serving service ;) Take a look at: http://pythonanywhere.com They provide host in Python, with a wide choice of framework to use/install ^^
5th Jul 2017, 3:03 AM
visph
visph - avatar
+ 4
respond to requests as in import requests? u can use requests module btw pip install requests like requests.get("https://www.sololearn.com") then continue your script
5th Jul 2017, 12:50 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 2
how about REST endpoints?
5th Jul 2017, 12:30 AM
Venkatesh Pitta
Venkatesh Pitta - avatar
- 3
Thanks, I have received good answers here.
5th Jul 2017, 11:17 AM
Eduardo Silva
Eduardo Silva - avatar
- 4
There are also filters to handle requests?
5th Jul 2017, 2:08 AM
Eduardo Silva
Eduardo Silva - avatar
- 6
Did you think that it was a good discussion? Vote it up! Thanks
5th Jul 2017, 11:19 AM
Eduardo Silva
Eduardo Silva - avatar
- 6
نعم
10th Jul 2017, 2:12 AM
hiba