Friday, March 04, 2016

NetBeans Java EE Tip #4 - RESTful Web Service JavaScript Client

In NetBeans Java EE Tip #3, I demonstrated how easy it is to create a RESTful web service using NetBeans.  In this tip, we will take a look at how quickly one can generate a JavaScript client for an existing RESTful web service.

To get started building the JavaScript client, right-click on the "Web Pages" folder of the NetBeans Web Application project, and choose "New"->"Web Services"->"RESTful JavaScript Client" (Figure 1).

Figure 1:  RESTful JavaScript Client

Next, provide a file name for the JavaScript file that will be generated for your client.  The wizard also allows you to choose a RESTful Web Service to utilize, and your choice of UI for the front end client site (Figures 2 and 3).

Figure 2:  Name JavaScript File & Choose Web Service

Figure 3:  Choosing Web Service

In Figure 4, you can see that I chose to use the Tablesorter UI for the front end. 

Figure 4:  Resulting UI Choice

Lastly, create the HTML page that will be utilized for your client.  Simply provide the name and optionally change the path to the file that will be generated.

Figure 4:  Name the HTML file

Once the wizard completes, your new HTML and JavaScript client will be ready to deploy and use!  

Figure 5:  HTML/JavaScript Client

The IDE will automatically reference the required JavaScript libraries to generate the client.  View the HTML sources, or click on the NetBeans project's "Remote Files" section to see which libraries are used.

Figure 6:  Remote Files in use by NetBeans Project

No comments:

Post a Comment

Please leave a comment...