python json rest api tutorial

Solutions on MaxInterview for python json rest api tutorial by the best coders in the world

showing results for - "python json rest api tutorial"
Maxwell
04 Jul 2016
1>>> import requests
2>>> import json
3>>> api_url = "https://jsonplaceholder.typicode.com/todos"
4>>> todo = {"userId": 1, "title": "Buy milk", "completed": False}
5>>> headers =  {"Content-Type":"application/json"}
6>>> response = requests.post(api_url, data=json.dumps(todo), headers=headers)
7>>> response.json()
8{'userId': 1, 'title': 'Buy milk', 'completed': False, 'id': 201}
9
10>>> response.status_code
11201
12