This will be similar to the client module from the Making REST requests with urllib recipe:
- Import the essential modules for working with RESTful APIs:
import urllib.request import urllib.parse import json
- There's a sequence of steps to make the POST request that will create a new, shuffled deck. This starts by defining the URL in pieces, by creating a ParseResult object manually. This will be collapsed into a single string later:
full_url = urllib.parse.ParseResult( scheme="http", netloc="127.0.0.1:5000", path="/dealer" + "/decks", params=None, query=None, fragment=None )
- Build a Request object from the URL, method, and headers:
request = urllib.request.Request( url = urllib.parse.urlunparse(full_url), method = "POST", ...