forked from jwinf843/http-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_requests.py
66 lines (50 loc) · 1.91 KB
/
http_requests.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
import requests
def perform_get_request():
"""Perform GET request to given URL and return the response"""
url = 'https://httpbin.org/get'
response = requests.get(url)
return response
def perform_get_request_with_params():
"""Perform GET request to given URL sending any parameter and return the response"""
# HINT: you should add the GET parameters at the end of the url
url = 'https://httpbin.org/get?q=python'
response = requests.get(url)
return response
def perform_post_request():
"""Perform POST request to given URL sending given data and return the response"""
url = 'https://httpbin.org/post'
data = {
'first_name': 'Guido',
'last_name': 'van Rossum'
}
response = requests.post(url, json=data)
return response
def perform_put_request():
"""Perform PUT request to given URL sending given data and return the response"""
url = 'https://httpbin.org/put'
data = {
'first_name': 'Guido',
'last_name': 'van Rossum'
}
response = requests.put(url, json=data)
return response
def perform_patch_request():
"""Perform PATCH request to given URL sending given data and return the response"""
url = 'https://httpbin.org/patch'
data = {
'first_name': 'Guido'
}
response = requests.patch(url, json=data)
return response
def perform_delete_request():
"""Perform DELETE request to given URL and return the response"""
url = 'https://httpbin.org/delete'
response = requests.delete(url)
return response
def perform_redirect_request():
"""Perform a request to a redirect URL and return the Location header that come in the response"""
# HINT: you should use the allow_redirects parameter while doing the request
url = 'https://httpbin.org/redirect/1'
response = requests.get(url, allow_redirects=False)
return response.headers['location']
print(perform_redirect_request())