# HTTP

return to Blockly Reference

# Introduction

This section explains the blocks that allow sending HTTP requests.

# HTTP Requests

There is one block that handles all type of requests. Depending on the required functionality it changes its design.

http-overview

# Option Toggles

There are three toggle buttons that allow the block to be small for simple requests and add further options to be used:

http-toggle

  • Clock: enables the timeout option
  • H: enables the header option and allows to provide headers during the request via a Dictionary
  • Q: enables the query option and allows to provide URI query parameters during the request via a Dictionary, the query parameters will be URI encoded

# HTTP Request GET

Function: Send an HTTP GET request to a server and receive the response

The simplest form is shown by default and accepts the destination URI as String.

http-get-simple

By activating the toggles the timeout, request headers and query parameters can be provided. Instead of creating a URI containing the query parameters, you can use the query parameter option and provide a Dictionary of query parameters. The provided parameters will automatically be URI encoded.

Here is an example also using a query parameter.

http-get-complex

See the POST-Request below for an example showing the use additional fields.

# HTTP Request POST

Function: Send an HTTP POST request to a server and receive the response

The simplest form is shown by default and accepts the destination URI as String and in comparison to the GET-Request adds a section for the payload which takes two parameters:

  • the MIME-type of the content to be sent
  • the content to be sent to the destination

For MIME-type application/json you can provide an object as content, and it will be converted to a JSON string. For application/x-www-form-urlencoded, you can provide a Dictionary and it will be URI encoded.

http-post-simple

Here is a more complex example that additionally sets a header and a timeout:

http-post-complex

# HTTP Request PUT

Function: Send an HTTP PUT request to a server and receive the response

The simplest form is shown by default and accepts the destination URI as String and is similar in functionality to the POST-Request:

  • the MIME-type of the content to be sent
  • the content to be sent to the destination

http-put-simple

Notice the construction of an object with a Dictionary also containing a List for the JSON payload.

# HTTP Request DELETE

Function: Send an HTTP DELETE request to a server and receive the response

The simplest form is shown by default and accepts the destination URI as String.

http-delete-simple

# Return to Blockly Reference

return to Blockly Reference