HTTP

Requesting and Receiving Information from the Web

What it is

The HTTP category contains blocks for communicating with web resources through HTTP requests.

These blocks allow the D1 R32 program to send a request, receive a response, and access different parts of that response.

What it does

The HTTP blocks allow a program to:

  • Send different types of HTTP requests.
  • Store a returned response.
  • Access the text returned by a request.
  • Read response headers.
  • Check a response status code.
  • Access cookies.
  • Obtain raw response content.
  • Work with JSON response data.

Example

A D1 R32 connected to a network can send a request and receive information:

D1 R32 → HTTP Request → Web Resource → HTTP Response → Program

Think of HTTP as a conversation: your program sends a request, and the web resource sends a response.


HTTP Blocks

The category contains three main blocks, but their drop-down menus provide several additional operations.

BlockBlock ImageWhat It DoesWhat the Options Mean
HTTP Request + Response
Sends an HTTP request and stores the returned response in response.Request method can be selected from GET, POST, PUT, DELETE, HEAD, and OPTION.
Response Content
Retrieves selected information from the stored HTTP response.Available options are text, headers, status_code, cookies, content, and json.
HTTP Request
Sends an HTTP request without visibly assigning the result to the response variable.Request method can be selected from GET, POST, PUT, DELETE, HEAD, and OPTION.

HTTP Requests and Web Communication Blocks

These blocks allow students to communicate with websites and web servers using HTTP requests. With them, an ESP32 can retrieve information, send data, update resources, delete information, and receive responses from online services.

They are useful for robotics and IoT projects that need to exchange information with websites, APIs, or cloud platforms.

1. HTTP Requests with Response Variables

#BlockBlock ImageWhat It DoesWhat the Options Mean
1HTTP GET Request
Sends a GET request to a website to retrieve information. The server's response is stored in response.URL: address of the website or API. get(): requests information without intending to modify the resource.
2HTTP POST Request Sends information to a server, commonly to create or submit a resource.URL: destination address. data: information sent to the server. The response is stored in response.
3HTTP PUT Request Sends information to a server to create or replace a resource.URL: destination address. data: information sent to the server. The exact effect depends on the server's API.
4HTTP DELETE Request Sends a request asking the server to delete a resource.URL: address of the resource to delete. The server decides whether the operation is allowed.
5HTTP HEAD Request Requests the response headers without requesting the response body.URL: website or resource address. Useful for checking information such as content type or modification details.
6HTTP OPTIONS Request Attempts to request the communication methods or options supported by a server or resource.URL: destination address. Note: The standard HTTP method is OPTIONS, but many MicroPython urequests libraries expose it as options() or may not implement it. Verify whether option() exists in the Clu-Bots library.

2. Read Information from an HTTP Response

After sending a request, the server returns a response. These blocks access different parts of that response.

#BlockBlock ImageWhat It DoesWhat the Options Mean
7Response Text
Returns the response body as readable text.Useful when the server returns plain text, HTML, or other text-based content.
8Response Headers Returns the HTTP headers sent by the server.Headers contain additional information such as content type, server details, and caching instructions.
9Response Status Code Returns the numerical HTTP status code indicating the result of the request.Examples: 200 means success, 404 means resource not found, and 500 means server error.
10Response Cookies Accesses cookies associated with the response, if supported by the library.Cookies can store information used by websites to maintain sessions or preferences. Availability depends on the urequests implementation.
11Response Content Returns the response body as raw bytes.Useful for receiving images, files, binary information, or data that needs further processing.
12Response JSON Accesses the JSON data returned by the server.JSON is a structured format used by APIs to exchange information. In many urequests implementations, this must be called as response.json() rather than accessed as a property.

3. HTTP Requests Without Storing the Response

These blocks send HTTP requests directly without assigning the returned response to a variable.

#BlockBlock ImageWhat It DoesWhat the Options Mean
13GET Request
Requests information from a website.URL: destination website or API. Returns a response object, even though it is not stored in a variable.
14POST Request Sends a POST request to submit information to a server.URL: destination address. No data argument is supplied in this example.
15PUT Request Sends a PUT request to create or replace a resource.URL: destination address. No data argument is supplied in this example.
16DELETE Request Sends a request to delete a resource.URL: address of the resource. The server determines whether deletion is permitted.
17HEAD Request Requests only the response headers from a website.URL: destination address. The response body is normally omitted.
18OPTIONS Request Attempts to request the HTTP options supported by the server.URL: destination address. Verify that the library supports the option() method; standard HTTP terminology uses OPTIONS.

Important notes for students

  • HTTP: Hypertext Transfer Protocol is a communication system used by websites and web services.
  • URL: The web address identifies the server and resource with which the ESP32 communicates.
  • GET: Retrieves information.
  • POST: Submits information, commonly to create a resource.
  • PUT: Creates or replaces a resource.
  • DELETE: Requests removal of a resource.
  • HEAD: Retrieves response headers without the body.
  • OPTIONS: Requests information about the communication methods supported by a resource.
  • Status codes: Help determine whether a request succeeded or encountered an error.
  • JSON: A common format for exchanging structured data between devices and web services.
  • Internet connection: The ESP32 must have a working network connection and access to the destination server.
  • Library dependency: urequests is a MicroPython HTTP library, not a standard Python library available in every environment.

1. HTTP Request and Response

[ INSERT BLOCK IMAGE HERE: HTTP Request + Response ]

The first block sends an HTTP request and stores the returned result in:

response

Conceptually:

SEND REQUEST → RECEIVE RESPONSE → STORE RESPONSE

The request type can be changed using the drop-down menu.

HTTP Request Options

OptionGenerated OperationBeginner-Friendly Meaning
GETurequests.get(...)Requests information from the specified web resource.
POSTurequests.post(...)Sends data using a POST request.
PUTurequests.put(...)Sends data using a PUT request.
DELETEurequests.delete(...)Sends a DELETE request.
HEADurequests.head(...)Sends a HEAD request.
OPTIONurequests.option(...)Sends the OPTION operation provided by Clu-Blocks Pro.

For beginners, start with GET.


2. Understanding Request and Response

HTTP communication can be understood using two fundamental concepts.

REQUEST

The D1 R32 asks a web resource for something:

D1 R32 → HTTP Request → Web Resource

RESPONSE

The web resource sends information back:

Web Resource → HTTP Response → D1 R32

Together:

REQUEST → WEB RESOURCE → RESPONSE

This response can then be saved in:

response

and examined using the Response Content block.


3. Reading the HTTP Response

[ INSERT BLOCK IMAGE HERE: Response Content ]

After the request has been made, the second block allows the program to select which part of the stored response to use.

The block begins with:

response get Response content

and provides several options.

Response Content Options

OptionGenerated PropertyWhat It Provides
textresponse.textText information from the response.
headersresponse.headersResponse header information.
status_coderesponse.status_codeThe response status code.
cookiesresponse.cookiesCookie information associated with the response.
contentresponse.contentThe response content using the block's content operation.
jsonresponse.jsonThe JSON-related response operation provided by Clu-Blocks Pro.

This makes the relationship easy to understand:

HTTP REQUEST

↓

response

↓

SELECT WHAT YOU NEED

↓

Text / Headers / Status Code / Cookies / Content / JSON


4. text

For beginners, text is a good place to start.

The generated operation is:

response.text

The basic concept is:

Web Response → Text → Program

HTTP → Response → Text → Serial Port → PC


5. status_code

The status_code option is particularly useful because it provides information about the result of the HTTP response.

The generated operation is:

response.status_code

Conceptually:

Make Request → Receive Response → Check Status Code

After communicating with another system, check the result before assuming that everything worked correctly.


6. headers, cookies, content, and json.

Headers

response.headers

Provides the response header information.

Cookies

response.cookies

Provides the cookie information associated with the response.

Content

response.content

Provides the response content using the corresponding content operation.

JSON

response.json

Provides the JSON-related operation available through the block.


7. HTTP Request Without Storing response

[ INSERT BLOCK IMAGE HERE: HTTP Request ]

The third block provides the HTTP request operation without the visible:

response =

assignment.

Its drop-down provides the same request-method choices:

OptionOperation
GETurequests.get(...)
POSTurequests.post(...)
PUTurequests.put(...)
DELETEurequests.delete(...)
HEADurequests.head(...)
OPTIONurequests.option(...)

Store the result

response = GET...

Perform the request

GET...


Understanding GET, POST, PUT, and DELETE.

GET

I want to request information.

POST

I want to send information using a POST request.

PUT

I want to send information using a PUT request.

DELETE

I want to send a DELETE request.

HEAD and OPTION

Begin with GET.


HTTP Requires a Network Connection

The conceptual sequence is:

D1 R32

↓

Wi-Fi / Network

↓

HTTP Request

↓

Web Resource

↓

HTTP Response

↓

Program


HTTP and Serial Port

Wi-Fi → HTTP GET → Response → Text → Serial Port → PC

Later:

Wi-Fi → HTTP → Response → Program Processing → Action


Quick Guide for Students

  • Do I want to request information? Start with GET.
  • Do I need to send information using POST? Select POST.
  • Do I want to keep the returned response? Use the block beginning with: response =
  • Do I want the returned information as text? Select: text
  • Do I need the response status code? Select: status_code
  • Do I need response header information? Select: headers
  • Do I need JSON-related response information? Select: json

Quick Reference

ConceptMain Idea
GETRequest information.
POSTSend a POST request with data where provided by the block.
PUTSend a PUT request with data where provided by the block.
DELETESend a DELETE request.
HEADSend a HEAD request.
OPTIONUse the OPTION operation provided by Clu-Blocks Pro.
responseStores the returned HTTP response in the assignment block.
textAccess response text.
headersAccess response headers.
status_codeAccess the response status code.
cookiesAccess response cookie information.
contentAccess response content.
jsonUse the JSON-related response operation provided by the block.