forked from naveenanimation20/Selenium-Python-TutorialsCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPIExamples.py
More file actions
33 lines (30 loc) · 966 Bytes
/
APIExamples.py
File metadata and controls
33 lines (30 loc) · 966 Bytes
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
import requests
import json
import jsonpath
# URL = 'https://reqres.in/api/users?page=2'
#
# '''get call'''
# response = requests.get(URL)
# print(response.url)
# print(response.status_code)
# print(response.content)
# print(response.headers['content-type'])
# # print(response.cookies)
# # print(response.encoding)
# # print(response.history)
# # print(response.elapsed)
# json_format = json.loads(response.text)
# print(json_format)
# first_name = jsonpath.jsonpath(json_format, 'data[0].first_name')
# print(first_name)
# assert first_name[0]== 'Michael'
# page = jsonpath.jsonpath(json_format, 'page')
# assert page[0] == 2
'''post call'''
URL = 'https://reqres.in/api/users'
file = open('/Users/NaveenKhunteta/PycharmProjects/Selenium-Demo/API/users.json', 'r')
json_data = file.read()
json_input = json.loads(json_data)
response = requests.post(URL, json_input)
print('status code: ', response.status_code)
print('response body', json.loads(response.text))