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 引数を使ってクエリパラメータを追加# 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| HTTPメソッド | 操作 | 説明 |
|---|---|---|
| GET | 読み取り | 郵便受けの中身を確認 |
| POST | 作成 | 新しい荷物を郵便受けに入れる |
| PUT | 更新 | 郵便受けの中の荷物をすべて新しい荷物に置き換える |
| 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')
requests パッケージには、各HTTPメソッドに対応する関数がありますdata 引数を使って、POSTリクエストまたはPUTリクエストにデータを渡します。Pythonを使ったAPI入門