eclipse-thingweb / node-wot

Components for building WoT devices or for interacting with them over various IoT protocols
https://thingweb.io
Other
161 stars 78 forks source link

Automatically use an HTTP POST when using uriVariables #385

Closed MartinMeyer1 closed 3 years ago

MartinMeyer1 commented 3 years ago

Here is an action in my TD: "set_relay": { "description": "Turn on/off the relay", "safe": false, "idempotent": false, "uriVariables": { "state":{ "type": "integer", "minimum": 0, "maximum": 1 } }, "forms": [ { "href": "/relay{?state}", "op": "invokeaction", "contentType": "application/json", "htv:methodName": "GET" } ] }

When I run "thing.invokeAction("set_relay", undefined,{ 'uriVariables': { 'state': '0' }})" the consumer says : "[binding-http] HttpClient (invokeResource) sending POST to http://thing_ip/relay?state=0". But I want it to be a http GET, that's why I set "htv:methodName": "GET".

If I change the TD to : "set_relay": { "description": "Turn on/off the relay", "safe": false, "idempotent": false, "forms": [ { "href": "/relay", "op": "invokeaction", "contentType": "application/json", "htv:methodName": "GET" } ] } It says: [binding-http] HttpClient (invokeResource) sending GET to http://thing_ip/relay

So I think it is related to the fact that I use a uriVariable.

Or maybe I am doing something wrong?

danielpeintner commented 3 years ago

I think you are right, handleUriVariables() duplicates the form but does NOT copy over "htv:methodName"

see https://github.com/eclipse/thingweb.node-wot/blob/963a7537aa39de7d4af683b313bba96fe8ac1d6e/packages/core/src/consumed-thing.ts#L493