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 인수로 전달합니다.Python으로 배우는 API 입문