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.
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:
Setting up HTTP resources
The following code can be used to create an HTTP resource:
Setting up variable resource-signals
given a backend-api located at 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:
Every read/write operation on one of the signals will only send HTTP messages to either www.my-server/api/light or 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 typestring
. This defines the content-type header of the HTTP message. Per default, this is"application/json"
writeMethod
, of typeHttpMethod
. This defines which HTTP Method (GET, POST, PUT, DELETE, UPDATE) is used when the signal is accessed using thewrite
method. Per default, this isHttpMethod.POST
.readMethod
, of typeHttpMethod
. This defines which HTTP Method (GET, POST, PUT, DELETE, UPDATE) is used when the signal is accessed using theread
method. Per default, this isHttpMethod.GET
.
Headers
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
All headers are insert using a single string, where the headers are separated using the character\n.
Performing Requests
Then the following code will send a POST request (the default write method for resource-signals) to www.my-server/api/helloWorld every 5 seconds, with a JSON payload
The input must always be a string.
Last updated
Was this helpful?