Try to Create REST API from HttpServlet in NWDS
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.
- From the ejb_demo module that you created on before example try to add Customer model class and initial data in the constructor class.
2. In CustomerInfoBean create Customer model instant and return it out.
Response data to JSON format by using Gson library
- 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.