Python เบื้องต้นสำหรับ API
Chris Ramakers
Engineering Manager
http://350.5th-ave.com/unit/243

# Append the query parameter to the URL string
response = requests.get('http://350.5th-ave.com/unit/243?floor=77&elevator=True')
print(response.url)
http://350.5th-ave.com/unit/243?floor=77&elevator=True
params เพื่อเพิ่ม query parameter# Create dictionary
query_params = {'floor': 77, 'elevator': True}
# Pass the dictionary using the `params` argument
response = requests.get('http://350.5th-ave.com/unit/243', params=query_params)
print(response.url)
http://350.5th-ave.com/unit/243?floor=77&elevator=True
http://350.5th-ave.com/unit/243| Verb | Action | คำอธิบาย |
|---|---|---|
| GET | Read | ตรวจสอบเนื้อหาในกล่องจดหมาย |
| POST | Create | ใส่พัสดุใหม่เข้าไปในกล่องจดหมาย |
| PUT | Update | แทนที่พัสดุทั้งหมดด้วยชิ้นใหม่ |
| DELETE | Delete | นำพัสดุทั้งหมดออกจากกล่องจดหมาย |
# GET = Retrieve a resource response = requests.get('http://350.5th-ave.com/unit/243')# POST = Create a resource response = requests.post('http://350.5th-ave.com/unit/243', data={"key": "value"}) # PUT = Update an existing resource response = requests.put('http://350.5th-ave.com/unit/243', data={"key": "value"})# DELETE = Remove a resource response = requests.delete('http://350.5th-ave.com/unit/243')
requestsdata เพื่อส่งข้อมูลใน POST หรือ PUT requestPython เบื้องต้นสำหรับ API