-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.py
40 lines (28 loc) · 841 Bytes
/
example.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
""" Example of API """
import json
import requests
url = "https://twondproductapi.onrender.com/api/v1"
""" body = {
"name": "python request",
"email": "python@gmail.com",
"phoneno": 1234567890,
"age": 21,
"address": "Gokuldham Society",
"city": "Dadar",
"state": "Maharashtra",
"pincode": 400001,
"password": "request",
}
jsonbody=json.dumps(body)
# register yourself
data = requests.post(url + "/register", data=jsonbody) """
params = {"email": "python@gmail.com", "password": "request"}
# login yourself
data = requests.get(url + "/login", params=params)
accesstoken = data.json()["Access Token"]
# view all products
products = requests.get(url + "/prod")
print(products.json())
# view yourself
myself = requests.get(url + "/me", headers={"Authorization": accesstoken})
print(myself.json())