I do not quite understand how the structure of the project should be, corresponding to the REST API. I currently have a simple servlet

public class Servlet extends HttpServlet { public class AuthServlet extends HttpServlet { } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { getServletContext().getRequestDispatcher("/index.jsp").forward(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { StringBuffer sb = new StringBuffer(); String line = null; BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) sb.append(line); try { String query=sb.toString(); Object o= ClientQueryService.queryHandler(query); response.setContentType("text/plain"); response.getWriter().write(o.toString()); } catch (JSONException e) { response.getWriter().write(e.toString()); } } } 

In the request, I pass the string json for example of the following form:

 {\"method\":\"addRoom\",\"allParamList\":[{\"type\":\"room\",\"id\":12,\"number\":22,\"cost\":33,\"capacity\":123,\"stars\":55,\"status\":\"FREE\"}]}"); 

The servlet sends json to the ClientQueryService class, which also returns the response as a json object. I need to remake this in rest api. After Google, I don’t really know what to do and what technologies to use. Can I make a servlet-based rest service? What to use? It seems there is a JAX-RS and its various implementations ... Can someone describe the chain of performing a simple query without some heaped frameworks? Just to work. For example add user. Type request is sent to the servlet, the servlet sends to some rest and it does something ...

  • Do you want to access a third-party REST service from a servlet, or should a servlet be a REST service? - Nofate
  • REST service should be my own. Just read somewhere that it can be done on the basis of a servlet. And so without a difference. - andreyatake
  • Can. Bind the servlet to urlu /room , implement the POST / GET / PUT / DELETE request processing, and remove the method property from the request body (the type of operation should be determined by the HTTP method). And here you will be a simple REST on a bare servlet. But the JAX-RS will have a more concise, supported code, and REST will come closer to the standards. - Nofate
  • As I understand it, in order to use JAX-RS, I only need to appropriately annotate the methods and that's it? For example @GET @Path ("/ user") public Task getTask (@QueryParam ("iuser") String user) {} And don't you have to write anything anywhere in the web.xml for example ?? And is it normal to transfer a json object (for example, a new user) in the request parameter, or is it only necessary to transfer individual data such as name, surname ...? That method over which I registered post the summary automatically will receive QueryParam? - andreyatake
  • Annotations only mark up your service. Anyway, the request is handled by a specific JAX-RS implementation (CXF, Resteasy, Jersey) and you need to configure it for your container (web.xml) or stand-alone application (then no web.xml will be at all). JSON (data) is transmitted in the request body. In query parameters, it is common to pass metadata like filters, flags, conditions. - Nofate

0