> For the complete documentation index, see [llms.txt](https://alfredo-reyes-montero.gitbook.io/iot-bosch/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alfredo-reyes-montero.gitbook.io/iot-bosch/devices/bosch-xdk-110/protocols/http/implementation/xdk-live.md).

# XDK Live

In Mita, HTTP is defined as a `many resource`. That means, multiple instances of this resource can exist, and each is given a unique name by the developer. All possible configuration items and signals for the HTTP resource are listed below.

```
connectivity many HttpRestClient {
    generator "org.eclipse.mita.platform.xdk110.connectivity.RestClientGenerator"
    validator "org.eclipse.mita.platform.xdk110.connectivity.RestClientValidator"

    /**
     * The underlying transport connectivity we use to send the data out. In the future we might also
     * support LoRa here.
     */
    required configuration-item transport : WLAN

    /**
     * The part of the endpoint URL common to all requests, e.g. "http://foobar.com/api/v1"
     */
    required configuration-item endpointBase : string

    /**
     * A custom header which is added to each HTTP request. Example:
     *   "X-Auth: MySecretToken\nX-Version: 1.0"
     */
    configuration-item headerContent : string

    signal resource(endpoint : string, contentType : string = "application/json", writeMethod : HttpMethod = HttpMethod.POST, readMethod : HttpMethod = HttpMethod.GET) : string

}
```

## Setup

HTTP requires a network connection to the destination server, to which the HTTP requests are sent. With the XDK, this network is usually established using Wi-Fi. The following code can be used to create a WLAN resource for use with HTTP:

```
setup wifi : WLAN {
    connection = Personal;
    ssid = 'mySSID';
    psk = 'myPassword';
}
```

## Setting up HTTP resources <a href="#id-3-2" id="id-3-2"></a>

All HTTP resources are generally set up with an endpointBase and a transport. The first configuration-item is a full URL, pointing to a desired endpoint base, such as [*http://www.my-backend.com:80*](http://www.my-backend.com:80). The configuration-item transport is the Wi-Fi resource, through which the HTTP messages are sent.

The following code can be used to create an HTTP resource:

```
setup googleRoot : HttpRestClient {
    transport = wifi;
    endpointBase = 'http://www.google.com:80';
    var root = resource('/');
}
```

## Setting up variable resource-signals <a href="#id-3-3" id="id-3-3"></a>

given a backend-api located at *[www.my-server.com:8080/api](http://www.my-server.com:8080/api)*, and the resources *light* and *temperature*, the following code would initialize an HTTP instance with the specified endpoints as resource-signals:

```
setup myServer : HttpRestClient {
    transport = wifi;
    endpointBase = 'http://www.my-server/api';
    var light = resource('/light');
  var temperature = resource('/temperature');
}
```

Every read/write operation on one of the signals will only send HTTP messages to either *[www.my-server/api/light](http://www.my-server/api/light)* or *[www.my-server/api/temperature](http://www.my-server/api/temperature)*.

So far, the resource-signals have been initialized with default settings (apart from the endpoint). They have the following optional parameters (and default values):

* `contentType`, of type `string`. This defines the content-type header of the HTTP message. Per default, this is`"application/json"`
* `writeMethod`, of type `HttpMethod`. This defines which HTTP Method (GET, POST, PUT, DELETE, UPDATE) is used when the signal is accessed using the `write` method. Per default, this is `HttpMethod.POST`.
* `readMethod`, of type `HttpMethod`. This defines which HTTP Method (GET, POST, PUT, DELETE, UPDATE) is used when the signal is accessed using the `read` method. Per default, this is `HttpMethod.GET`.

### Headers <a href="#id-3-5-1" id="id-3-5-1"></a>

For an HTTP resource, additional headers can be set using the optional configuration-item `headerContent`. The code below is an example for setting the headers

* X-Auth: MySecretToken
* X-Version: 1.0

for messages which are sent using the specifically setup HTTP resource

```
setup myServer : HttpRestClient {
    transport = wifi;
    endpointBase = 'http://www.my-server/api';
  headerContent = 'X-Auth: MySecretToken\nX-Version: 1.0';
    var light = resource('/light');
}
```

All headers are insert using a single string, where the headers are separated using the character`\n.`

## Performing Requests <a href="#id-3-4" id="id-3-4"></a>

Then the following code will send a POST request (the default write method for resource-signals) to *[www.my-server/api/helloWorld](http://www.my-server/api/helloWorld)* every 5 seconds, with a JSON payload

```
every 5 seconds {
  myServer.light.write('{"hello": "world"}');
}
```

The input must always be a string.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://alfredo-reyes-montero.gitbook.io/iot-bosch/devices/bosch-xdk-110/protocols/http/implementation/xdk-live.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
