LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing an Array to VI Exposed in REST Web Service

It appears that the REST Web Service does not support passing an array via the query parameters of an HTTP request.


For instance, I would like to do the following:

 

1. Send GET http://127.0.0.1:8002/driver_interface/summation?Array=1&Array=2&Array=3

2. LabVIEW recieves its "Array" input as [1, 2, 3]

 

I noticed that when I wire the "Array" to the connector pane, it is not exposed as a query parameter.  I could write my own utility which uses the "Read Request Variable" VI; on the server-side VI I would read the "Array" request variable and turn the "1 2 3" string into an array of numbers.

 

Am I correct that the REST web service does not have this array query parameter support natively?  (I also noticed the same thing with cluster inputs: they are not exposed via the query parameters.)


Thanks!
Darshan

0 Kudos
Message 1 of 7
(4,906 Views)

Hi darshahlu,

 

I haven't used REST before, but from what I can find it sounds like it can't return arrays directly. I found a similar question on another forum. It looks like they came to a similar solution of returning a string, then converting that to an array. 

 

I hope this helps!

Emily C
Applications Engineer
National Instruments
0 Kudos
Message 2 of 7
(4,850 Views)

Returning arrays and clusters is supported.  Here is an example JSON output from a VI exposed via the REST service.  It is returning an array and the error cluster:

 

{
"Array": [
"hello",
"jello"
],
"error out": {
"status": true,
"code": -1073807343,
"source": "VISA Open in subtract.vi->subtract.vi.ProxyCaller"
},
}

 

My question has to do with providing arrays as inputs to the VI.  I noticed that if I had an array input wired on the VI's connector pane, that it was not automatically exposed in the "query parameters".

 

I can provide an array of data to the LabVIEW VI; its just that LabVIEW does not automatically convert incoming data to the array data type, as it does with other data types (booleans, numerics, etc).  I would have to write LabVIEW code to do the parsing manually.  I could use "Read Form Data", "Read Postdata" or "Read Request Variable".

 

For now, I will try to use the data types which are automatically converted.

0 Kudos
Message 3 of 7
(4,776 Views)

Hey Darshan,

 

In LabVIEW 2013 there is an API for handling JSON.  This is one pretty easy way for you to pass in your arrays and handle them in your Web Service.  If you are using LabVIEW on the client side, you can use the JSON API to flatten your array to a JSON string and then on the server side, you can use the same API to unflatten.  You can also handle clusters in a similar way. 

 

Let us know if you have any questions with this approach!

 

KiraT

0 Kudos
Message 4 of 7
(4,754 Views)

can you please send some VI's related to the above approch to pass an arguments

0 Kudos
Message 5 of 7
(3,930 Views)

Sumeeth, see example VI below using Unflatten from JSON

 

screen.png

0 Kudos
Message 6 of 7
(3,864 Views)

Sumeeth, here is an example using the query parameters approach.  Note that this won't work with arrays or clusters.  It only works with simple data types (floats, strings, booleans, etc.)

 

To make an input a query parameter, you simple wire it in the connector pane.

 

screen2.png

0 Kudos
Message 7 of 7
(3,861 Views)