https://httpbin.org/의 REST API 스펙을 테스트하는 예제입니다.
- Python version:
3.8
/delete
import json, requests
url = 'https://httpbin.org/delete'
r = requests.delete(url, headers={"Content-Type": "application/json"})
print(r.json())
/get
import json, requests
url = 'https://httpbin.org/get'
r = requests.get(url, headers={"Content-Type": "application/json"})
print(r.json())
/post
import json, requests
url = 'https://httpbin.org/post'
r = requests.post(url, headers={"Content-Type": "application/json"})
print(r.json())
/basic-auth/{user}/{passwd}
import json, requests
import base64
userPass = 'somuser:sompass'.encode()
b64Val = base64.b64encode(userPass).decode("utf-8")
url = 'https://httpbin.org/basic-auth/somuser/sompass'
r = requests.get(url, headers={"Content-Type": "application/json", "Authorization": "Basic %s" % b64Val})
print(r.json())
/ip
import json, requests
url = 'https://httpbin.org/ip'
r = requests.get(url, headers={"Content-Type": "application/json"})
print(r.json())
/base64/{value}
import json, requests
import base64
text = 'Somm is awesome'.encode()
b64Val = base64.b64encode(text).decode("utf-8")
url = 'https://httpbin.org/base64/' + b64Val
r = requests.get(url, headers={"Content-Type": "text/html"})
print(r.text)