liveBook · Manning

REST

As explained in Investing for Programmers

A REST API is a web interface that exposes resources and operations through the conventions of the Representational State Transfer architectural style.

REST is a web interface for exposing resources and operations through Representational State Transfer conventions. In Python, a REST call sends structured parameters to an endpoint and receives a response that must be checked rather than assumed successful. section 9.2.2

A practical REST workflow includes:

  • Build a JSON-compatible dictionary representing titles, properties, or content. section 9.2.2
  • Send the payload with an HTTP method such as POST for page creation or PATCH for page editing. section 9.2.2
  • Validate the returned status code and extract the resource identifier needed by later requests. section 9.2.2
  • Split content when the remote service imposes a size limit, stopping if a write fails. section 9.2.2

Creating and updating a Notion page

A Python routine posts a title and database identifier to create a page, receives its page ID, then patches the page’s blocks with JSON content. It writes long responses in 2,000-character chunks and stops after an unsuccessful update. section 9.2.2

def create_page(title_properties: dict) -> str:
    create_url = "https://api.notion.com/v1/pages"
    payload = {"parent": {"database_id": DATABASE_ID}, 
               "properties": title_properties}
    res = requests.post(create_url, headers=headers, json=payload)
    if res.status_code == 200:
        print(f"{res.status_code}: Page created successfully")
    else:
        print(f"{res.status_code}: Error during page creation")
    return res.json()["id"]

Inspect the compact Python implementation that constructs a page-creation payload, calls an endpoint, checks status 200, and returns the new page ID. section 9.2.2

How Investing for Programmers covers it

How deep it goes
Explains payload construction, HTTP methods, status checks, identifiers, and chunked writes, but does not develop REST architecture broadly.
Examples
Uses Notion page creation, block updates, title properties, JSON dictionaries, and 2,000-character content chunks.
What it assumes
Assumes basic Python dictionaries and functions while demonstrating JSON payloads, endpoints, response codes, and resource identifiers.
What you can do after
Apply it via Python requests to create resources, update content, validate responses, and handle service size limits.
How it connects
Ties REST APIs to JSON, HTTP status codes, Python requests, database identifiers, and Notion pages.

Also explained in

Compare how 22 books explain REST →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Investing for Programmers. The section links point to the parts of the book it draws on.