-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathcfe_pure_api.py
85 lines (63 loc) · 1.77 KB
/
cfe_pure_api.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import json
import requests # http requests
BASE_URL = "http://127.0.0.1:8000/"
ENDPOINT = "api/updates/"
def get_list(id=None): #--> Lists all this out
data = json.dumps({})
if id is not None:
data = json.dumps({"id": id})
r = requests.get(BASE_URL + ENDPOINT, data=data)
print(r.status_code)
status_code = r.status_code
if status_code != 200: # not found
print('probably not good sign?')
data = r.json()
return data
def create_update():
new_data = {
'user': 1,
"content": "Another more cool content"
}
r = requests.post(BASE_URL + ENDPOINT, data=json.dumps(new_data))
print(r.headers)
print(r.status_code)
if r.status_code == requests.codes.ok:
#print(r.json())
return r.json()
return r.text
print(get_list())
# print(create_update())
def do_obj_update():
new_data = {
"id": 3,
"content": "awesomer"
}
r = requests.put(BASE_URL + ENDPOINT, data=json.dumps(new_data))
# new_data = {
# 'id': 1
# "content": "Another more cool content"
# }
# r = requests.put(BASE_URL + ENDPOINT, data=new_data)
#print(r.headers)
print(r.status_code)
if r.status_code == requests.codes.ok:
#print(r.json())
return r.json()
return r.text
def do_obj_delete():
new_data = {
"id": 3
}
r = requests.delete(BASE_URL + ENDPOINT, data=json.dumps(new_data))
# new_data = {
# 'id': 1
# "content": "Another more cool content"
# }
# r = requests.put(BASE_URL + ENDPOINT, data=new_data)
#print(r.headers)
print(r.status_code)
if r.status_code == requests.codes.ok:
#print(r.json())
return r.json()
return r.text
# print(do_obj_update())