Try to Create REST API from HttpServlet in NWDS

Thanapuet Kaewmanee
2 min readJun 9, 2020

--

Prerequisites: Understanding these below content before you continue this example.

- Create Java Web Application using WEB Module and EJB in NWDS

- Add External Library to EJB Module — NWDS

As first you created “Web application using WEB Module and EJB Module” and “External Library and Import to your EJB Module” for this example we will try to create an easy REST API by using HttpServlet.

Create a java class model.

  1. From the ejb_demo module that you created on before example try to add Customer model class and initial data in the constructor class.
Create a package
Create a java model

2. In CustomerInfoBean create Customer model instant and return it out.

Define CustomerInfoLocal Interface
Implement and override

Response data to JSON format by using Gson library

  1. In CustomerInfoServlet Import ext_demo module (external library module that we have created in before example)

2. Create Gson instant for convert data in a java class to JSON format.

3. The doGet method does convert data from java class to JSON format and the response it out.

Run and see the result

Run the result in the browser

--

--

Thanapuet Kaewmanee
Thanapuet Kaewmanee

No responses yet