Class ApiServlet

  • All Implemented Interfaces:
    Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig, UserContext

    public class ApiServlet
    extends javax.servlet.http.HttpServlet
    implements UserContext
    Subclass ApiServlet and implement init by calling registerController with all your controller classes. Example controller class:
     public class MyApiController {
    
         @Get("/v1/api/objects")
         @JsonBody
         public List<SomePojo> listObjects(
             @RequestParam("query") Optional<String> query,
             @RequestParam("maxHits") Optional<Integer> maxHits
         ) {
             // ... this is up to you
         }
    
         @Get("/v1/api/objects/:id")
         @JsonBody
         public SomePojo getObject(@PathParam("id") UUID id) {
             // ... this is up to you
         }
    
         @Post("/v1/api/objects/")
         @SendRedirect
         public String postData(
             @JsonBody SomePojo myPojo,
             @SessionParameter("user") Optional<User> user
         ) {
             // ... do your thing
             return "/home/";
         }
     }
     
    See Also:
    Serialized Form
    • Constructor Detail

      • ApiServlet

        public ApiServlet()
      • ApiServlet

        public ApiServlet​(Object controller)
    • Method Detail

      • service

        protected void service​(javax.servlet.http.HttpServletRequest req,
                               javax.servlet.http.HttpServletResponse resp)
                        throws IOException
        Overrides:
        service in class javax.servlet.http.HttpServlet
        Throws:
        IOException
      • registerController

        public void registerController​(Object controller)
      • registerControllers

        public void registerControllers​(Object... controllers)
      • registerControllerList

        public void registerControllerList​(List<Object> controllers)
      • init

        public void init​(javax.servlet.ServletConfig config)
                  throws javax.servlet.ServletException
        Specified by:
        init in interface javax.servlet.Servlet
        Overrides:
        init in class javax.servlet.GenericServlet
        Throws:
        javax.servlet.ServletException
      • setupActions

        protected void setupActions()
      • registerMBeans

        public void registerMBeans()
      • registerMBeans

        public void registerMBeans​(MBeanServer mBeanServer)
      • setTimerRegistry

        public void setTimerRegistry​(TimerRegistry timerRegistry)
        This method lets you plug in metrics for measuring which actions are executed and how long they take. See TimerRegistry