This content is not available in your preferred language.

The content is shown in another available language. Your browser may include features that can help translate the text.

Creating Web Services and Web Applications With HTTP Get and Post Using G Web Development Software and LabVIEW

Updated Apr 5, 2024

Environment

Software

  • LabVIEW
  • G Web Development Software

Using NI softwares may shorten the development period because they promote digital transformation (DX) and allow developing web services and applications for internal and external use. For example, you can build web services and web applications using LabVIEW and G Web Development Software (GWDS). We will use NI Web Server installed with these software to set up a PC as a server and see how basic HTTP communication works. Here, we will also see how to host a web application (*.html) created with GWDS and access it using a browser from a client PC existing in the same network as the host PC. Finally, we will check how to connect and communicate with Web service using HTTP requests.

Table of contents

  1. Configuring the NI Web Server and Verifying Basic Server Functionality
  2. Creating web applications with GWDS
  3. Creating a web service with LabVIEW
  4. Linking web applications and web services using HTTP requests (GWDS)
  5. Send POST request to a web service(LabVIEW)

This document uses the following software. (you will need a valid licence to used them).

*The 64-bit version of LabVIEW is only available in English, and there is no Japanese version.

ni web8.PNG


 

  1. Configuring the NI Web Server and Verifying Basic Server Functionality

NI Web Server is installed when you install LabVIEW or GWDS, and can be access from Windows search box as shown below.

  1. Check this manual for basic settings and configurations.

ni web1.PNG

  1. From the Remote tab of NI Web Server Configuration, select Enable cross-origin source sharing (CORS) for all origins to allow web service to be accessible.
 

 

ni web7.PNG

 

We will use the NI Web Server with an insecure remote access configuration. Refer to the below articles to understand basics NI Web Server's features (hosting files and, communicating with NI Web Server using HTTP requests)

  1. Creating web applications with GWDS

This section will Web applications are created using GWDS (or NXG Web Module, the predecessor of GWDS). Start GWDS and create a Web Application Project.
The techniques used i\when creating web applications in GWDS are similar to those commonly used in LabVIEW project such as state machines and queued message handlers (You can also create a Queued Message Handler for the Web project in GWDS).

1gwds.png





In this example, a state machine with 5 cases uses( You can check the content of this Webb App project by downloading the Attachment files at the bottom of this article.)

6cases.png

The web application UI displays as below in a browser. you can enter GET / POST requests and click GET or POST button respectively to execute the HTTP requests.

index.PNG


 

  1. Creating web service with LabVIEW  

 

  1. This section wll explai how to create Web services in LabVIEW. Launch LabVIEW and create a new project

NewProject.png

 

  1. Follow the instructions on this manual to create web service and add multiple web service resoures in you project.

webservice.png

 

  1. As explain in the manual , right-click WebService on the project explorer ans select Application Web Server>>start (Debug Server)  to start the web service.

index2.PNG

 

  1. Right-click on Add.vi >> Show method URL... to display HTTP Method URL for the selected VI.

The HTTP Method URL will change based on the Available Server selected:  debug server (default port 8001), application server (default port 8080), and NI web server (default port 80) .

  1. Copy and paste the URL in a browser to see the results(input values in a and b controls)  

image.pngindex4.PNG

 

  • In the above example the HTTP Method URL is http://127.0.0.1:8001/WebService/Add?b={value}&a={value} . 127.0.0.1 indicates that  you are accessing the web service  on the same PC(server PC). When executing this URL on the server PC, you can use 127.0.0.1 or Localhost.
  • To access this web service from the browser of a different computer(not the host PC), change  127.0.0.1  to the IP address of the server hosting the web service. In this example, we entered the server IP 10.128.1.103 and checked the operation from another PC.
  • The 8001 part indicates the debug server as shown below. If you publish to the NI Web server using the method described in this manual, the port will be 80. So, make sure to check your NI Web server configuration and choose the proper port.

ServerPort.png


 

  1. Linking web applications and web services using HTTP requests(GWDS)

In this section, we will check the operation of Web services created with G Web Development Module. ( step 2 )

  1. Open your web application project and select Run in broswer

index6.PNG


Similar as LabVIEW web services, Web UI created with GWDS can also be run from a client PC connected to the same network as the server PC. To achieve this, follow instructions on this article to configure your server accordingly.
 

  1. Send POST request to a web service (LabVIEW)

Create a POST request like the one below and use Read Postdata.vi to read the buffer data sent during the POST request. After processing on the web service, send the data to the client with Write Response.vi. Here, flatten to JSON and unflatten from JSON functions are used to exchange data in JSON format. Since it is not possible to exchange Japanese character strings with the HTTP method, URL encoding/decoding is required.

index7.PNG

When executing the above POST request (PlusOneArray) from the Web UI created in GWDS, it will display as follows. Enter data in JSON format in the buffer (POST) part and click the POST button. The response will be displayed in the body(POST box.

execution.png