-
REST API 코딩 테스트를 마주한다면? (python, 작성중)카테고리 없음 2022. 2. 11. 14:38
실습 사이트
https://jsonplaceholder.typicode.com/
JSONPlaceholder - Free Fake REST API
{JSON} Placeholder Free fake API for testing and prototyping. Powered by JSON Server + LowDB. Tested with XV. As of Oct 2021, serving ~1.7 billion requests each month.
jsonplaceholder.typicode.com
GET 이용 템플릿
import requests #import requests import json url = "https://jsonplaceholder.typicode.com/posts" # url = "URL" response = requests.get(url).json() # response = requests.get(url) #print(response) for i in response: print(i['title']) # json 형식으로 원하는데로 출력
POST 이용 템플릿
import requests import json url = "https://jsonplaceholder.typicode.com/posts" newItem = { "id": 4, "content": "Python", "completed": True } response = requests.post(url, data=newItem).json() #데이터와 함께 넘겨주기 print(response)