-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestful_API.py
More file actions
33 lines (26 loc) · 1.04 KB
/
Restful_API.py
File metadata and controls
33 lines (26 loc) · 1.04 KB
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 the requests library
url = "https://student-info-api.netlify.app/.netlify/functions/submit_student_info" #sets the URL for the API endpoint
Data = {
"UCID" : "mm2734",
"first_name" : "Maryam",
"last_name" : "Mughal",
"github_username" : "mmaryam28",
"discord_username" : "maryamm7817",
"favorite_cartoon" : "Mr Bean",
"favorite_language" : "Python",
"movie_or_game_or_book" : "Fast and Furious",
"section" : "103",
} #data information
try:
#Send POST request with the data
post_resp = requests.post(url, json=Data)
print("POST Status: ", post_resp.status_code)
print("POST Response: ", post_resp.text)
#Send GET request with UCID + section as params
params = {"UCID": "mm2734", "section": "103"}
get_resp = requests.get(url, params=params)
#Prints GET results
print("GET Status: ", get_resp.status_code)
print("GET Response: ", get_resp.text)
except requests.exceptions.RequestException as e:
print(f"Request failed: {e}")