Python API 入門
Chris Ramakers
Engineering Manager
http://350.5th-ave.com/unit/243

# 將查詢參數直接接在 URL 字串後
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_params = {'floor': 77, 'elevator': True}
# 透過 `params` 參數傳入字典
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 | Description |
|---|---|---|
| GET | Read | 查看信箱內容 |
| POST | Create | 投遞新包裹進信箱 |
| PUT | Update | 以新包裹取代所有舊包裹 |
| DELETE | Delete | 移除信箱內所有包裹 |
# GET = 取得資源 response = requests.get('http://350.5th-ave.com/unit/243')# POST = 建立資源 response = requests.post('http://350.5th-ave.com/unit/243', data={"key": "value"}) # PUT = 更新現有資源 response = requests.put('http://350.5th-ave.com/unit/243', data={"key": "value"})# DELETE = 移除資源 response = requests.delete('http://350.5th-ave.com/unit/243')
requests 套件中都有對應方法。data 參數在 POST 或 PUT 請求中傳遞資料。Python API 入門