liveBook · Manning

Requests

As explained in Coding with AI

Requests is a Python library for sending HTTP requests and receiving responses from web services.

Use requests to send an HTTP GET request to an API, display the response, and handle likely failures through a staged prompting workflow. section 9.5.1

Build the task in three practical passes:

  • Decompose the goal into smaller subtasks: initialize the request, display the response body, and handle errors. section 9.5.1
  • Ask focused questions about GET-request best practices, response display, network errors, and non-200 responses. section 9.5.1
  • Evaluate each response, revise unclear prompts, and treat generated guidance as material requiring developer judgment. section 9.5.1

Prompt sequence

Start with: “Decompose the following task into a series of smaller, manageable steps. The goal is to send an HTTP GET request to an API using Python’s requests library, display the response, and handle potential errors.” Then request focused explanations for initialization, response-body display, and network or non-200 errors. section 9.5.1

Figure 9.6 A chain-of-thought prompt gets the model to reason out a problem like a human would. You break down the problem and experiment with answers until you get the results you desire.
A diagram of a diagram

Description automatically generated

Use the figure to visualize decomposition, experimentation, and iterative refinement as a single prompting loop. section 9.5.1

How Coding with AI covers it

How deep it goes
Explains decomposition, prompt design, and iterative evaluation, without detailing the library’s internal implementation.
Examples
Demonstrates decomposition and focused prompts for initializing requests, displaying responses, and handling errors.
What it assumes
Assumes recognition of Python, HTTP GET requests, APIs, and response errors while supporting stepwise clarification.
What you can do after
Apply it via Python’s requests library by decomposing an API task and refining prompts for implementation guidance.
How it connects
Connects requests with HTTP GET requests, APIs, response bodies, network errors, non-200 responses, and prompt engineering.

Also explained in

Compare how 6 books explain requests →

Related concepts

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