Module aeonics.http
Package aeonics.http

Class Endpoint.Rest

  • Enclosing class:
    Endpoint

    public abstract static class Endpoint.Rest
    extends Endpoint
    This is the base REST endpoint.

    There are two recommended ways to create your own endpoint. The first method allows to provide the data processing function and registers automatically the template in the factory and the instance in the registry:

     Endpoint.Rest.Type endpoint = new Endpoint.Rest() { } // <-- note the '{ }' to create a new anonymous class
         
         .template() // <-- create the template and register it in the factory
         
         // add all your template documentation
         .summary("Says hello to the world")
         
         .create() // <-- create an instance of the entity and register it in the registry
         .<Rest.Type>cast()
         
         // set the rest endpoint logic
         .process(() -> Data.map().put("hello", "world")) // <-- the endpoint logic
         
         // set the generic endpoint settings
         .url("/hello")
         .method("GET");
     

    If you need more control over the endpoint behavior such as private member variables or multiple methods, then you need to declare a custom entity end register it before calling the template method:

     public static class Hello extends Endpoint.Rest.Type {
         private String who = "world";
         private Data hello() { return Data.map().put("hello", who); }
         public Data process() { return hello(); }
     }
     
     Endpoint.Rest.Type endpoint = new Endpoint.Rest() { } // <-- note the '{ }' to create a new anonymous class
         
         // register the custom entity before calling the template
         .target(Hello.class)
         .creator(Hello::new)
         
         .template() // <-- create the template and register it in the factory
         
         // add all your template documentation
         .summary("Says hello to the world")
         
         .create() // <-- create an instance of the entity and register it in the registry
         
         // set the generic endpoint settings
         .url("/hello")
         .method("GET");
     
    • Constructor Detail

      • Rest

        public Rest()
    • Method Detail

      • defaultTarget

        protected java.lang.Class<? extends Endpoint.Rest.Type> defaultTarget()
        Description copied from class: Item
        Returns the default target entity type. This method should be implemented by subclasses to specify the target entity type.
        Specified by:
        defaultTarget in class Item<Endpoint.Type>
        Returns:
        the default target entity type
      • defaultCreator

        protected java.util.function.Supplier<? extends Endpoint.Rest.Type> defaultCreator()
        Description copied from class: Item
        Returns the default target entity creator. This method should be implemented by subclasses to specify the entity creator.
        Specified by:
        defaultCreator in class Item<Endpoint.Type>
        Returns:
        the default target entity creator
      • template

        public Endpoint.Template template()
        Description copied from class: Item
        Returns the template to build the target entity.

        This method should ultimately be used to provide the final entity template. Although, it may also provide a partial template that subclassed may complement.

        Overrides:
        template in class Endpoint
        Returns:
        the matching entity template