-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_api_2_clt.py
35 lines (28 loc) · 932 Bytes
/
basic_api_2_clt.py
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
# client in python
import requests
# pip install requests
'''
from flask import request ===> used in server side
import requests ==> used in client side
'''
r = requests.get(url='http://127.0.0.1:5000/')
print(r)
print(r.status_code)
print(r.json())
result = r.json()
print(result['message'])
print(result.get('message'))
print('-------------------------')
r = requests.post(url='http://127.0.0.1:5000/',
json={'name': 'Ahmed'})
print(r.status_code)
print(r.json().get('message'))
print('-------------------------')
print('Call weather service')
city = 'Istanbul'
r = requests.post(url='http://127.0.0.1:5000/weather',
json={'city': city})
print('the temperature in {} is {}'.format(city, r.json().get('temperature')))
r = requests.get(url='http://127.0.0.1:5000/weather')
for city, temp in r.json().get('temperature').items():
print('City: {}\t Temperature: {}'.format(city, temp))