-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek_10_server.py
More file actions
45 lines (36 loc) · 1.28 KB
/
week_10_server.py
File metadata and controls
45 lines (36 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from bottle import route, run, request
@route('/hello')
def hello():
return "Hello World!"
@route('/')
def index():
""" Display welcome & instruction messages """
return "<p>Welcome to my extra simple bottle.py powered server !</p> \
<p>The Web service can convert a string into UPPERCASE or lowercase. \
There are two ways to invoke the web service :\
<ul> \
<li>http://localhost:8080/convert/action_name/your string</li> \
<li>http://localhost:8080/convert?action=action_name&sentence=your string</li>\
</ul> \
action_name can be UPPER or lower."
@route('/convert/<action>/<sentence>')
def conversion(action, sentence):
if action == "UPPER":
sentence = sentence.upper()
elif action == "lower":
sentence = sentence.lower()
else:
sentence = "There is something wrong with the service call."
return sentence
@route('/convert')
def conversion_parameters():
action = request.query.action
sentence = request.query.sentence
if action == "UPPER":
sentence = sentence.upper()
elif action == "lower":
sentence = sentence.lower()
else:
sentence = "There is something wrong with the service call."
return sentence
run(host='localhost', port=8080, debug=True)