---
url: /statelake/scripting-reference/http-scripting.md
---

# HTTP Scripting

An acronym for **Hypertext Transfer Protocol**, **HTTP** is the foundation of the World Wide Web, and is used to load webpages using hypertext links.

**HTTP** is an application layer request-response protocol, designed to give users a way to transfer information between networked devices, and runs on top of other layers of the network protocol stack.

**HTTP Requests** are messages sent by the client to initiate an action on a server, which prompts the server to send back a response message to the client. The client may send multiple requests to the server, repeating the cycle as required. Every request is considered to be a separate transaction - there is no inherent state maintained about the user, and a connection is not held open between requests. To get around this limitation, servers use cookies and session headers.

**HTTP Responses** are the replies that are fired back from a server in response to the **HTTP Request**. Responses will contain a reply code that informs the requestor about the status of the request, along with any relevant or requested resources.

**HTTP Requests** and **HTTP Responses** have a similar structure.

They both have a **Start-Line** – for a request this is a **Request-Line**, and for responses this is a **Status-Line**. This **Start-Line** is followed by optional **Message Headers**, a **Blank Line**, and an optional **Message Body**.

The **Start-Line** and **Message Headers** are collectively known as the *head* of the requests, whereas its payload (**Message Body**) is known as the *body*.

Within **Statelake**, the **HTTP** object supports a number of properties and methods to enable **Custom Script** **Actions** and **Map** events to invoke **HTTP** requests, and take appropriate action in response to the results of those requests.

To simplify and support the use of the **HTTP** object, an **HTTP** **Connections** type is available on the **Statelake** configuration hierarchy. **HTTP Connections** objects are used to configure properties of the **HTTP** servers, and services invoked from the script object.

The **HTTP** script object is fully integrated with **Action Logging**, with request and response traffic resulting from use of the object being fully incorporated in the **HTTP** **Trace** tab of **Action Logs** as appropriate, as shown below.

The basic operation of the **HTTP** object is as follows -

* Set the **HTTP Connection**
* Open a URL with the required **HTTP** method
* Set request headers/parameters (*optional*)
* Supply request content (*optional*)
* Send the request
* Process the response (*optional*)

## HTTP Connections

You can either identify the **HTTP** server and connection details through the **HTTP Connections** screen form, or programmatically. The first step in using the **HTTP** object in a script **Action** or **Map** event, is to identify the **HTTP Connection** object that contains the configuration details of the **HTTP** service to be invoked.

For example, an **HTTP Connection** has been created called **NZ Customs Rates**. This connection has been appropriately configured for the NZ Customs web service API. The properties of that connection object will include the appropriate OAuth credentials, and any header or query parameter values that may be required for a successful connection.

A link to this **HTTP Connection** is then created in either a **Map** script or an **Action Custom Script**.

Please make sure to review [HTTP Connections](/statelake/administering-statelake/designer/data-connections/http-connections/).
