helidon icon indicating copy to clipboard operation
helidon copied to clipboard

Routing V2 API design

Open Verdent opened this issue 3 years ago • 5 comments

Create new or update new Routing API design of the one used in PoC of Tomas Langer.

  • [x] Separate WebSocket from WebServer (standalone module, that is only used when on classpath)
  • [x] Separate HTTP/2 from WebServer (standalone module)
  • [x] #4085
  • [x] Single HTTP route that works both on HTTP/1 and HTTP/2
  • [x] Explicit routes that are only HTTP/1 or only HTTP/2
  • [ ] https://github.com/oracle/helidon/issues/81 (deferred to after 3.0)
  • [x] https://github.com/oracle/helidon/issues/1866
  • [x] #1865

Verdent avatar Sep 02 '21 14:09 Verdent

May I suggest supporting some sort of RoutePath interface that can be put into an annotation when implemented by an enum constant and also used to reverse-route links.

This makes refactoring so much easier.

This is only a concept, I have only tried this in smaller projects.

    interface RoutePath<X extends Enum> {
        String pattern();
        
        default String link(Map<X, String> params) {
            this.pattern ... replace params
            ... check all params defined
        }

        default String link(X param, String value) {
            return link(Map.of(param, value));
        }
        default String link(X param1, String value1, X param2, String value2) {
            return link(Map.of(param1, value1, param2, value2));
        }
    }

    enum MyParams {
        BOOK,
        CUSTOMER
    }

    class Controller {

        @POST(MyPaths.HOME)
        void home(ServerRequest req, ServerResponse resp) {
            String link = MyPaths.CUSTOMER.link(MyParams.CUSTOMER, "123");
        }
    }

    enum MyPaths implements RoutePath<MyParams> {
        HOME("/home"),
        CUSTOMER("/customer/{customer}");

        private final String pattern;

        MyPaths(String pattern) {
            this.pattern = pattern;
        }

        @Override
        public String pattern() {
            return this.pattern;
        }
    }

lambdaupb avatar Apr 22 '22 14:04 lambdaupb

@lambdaupb in order words typed route paths. This would mean overload Routing.Rules @tomas-langer thoughts ?

romain-grecourt avatar Apr 22 '22 17:04 romain-grecourt

The one problem I have is nested paths that appear in controllers with a path and controller methods with their own.

I ended up registering all controllers (Helidon Services, very unfortunate naming) at "/" and use the full path on the method.

I hope the path matching is smart and uses some sort of trie.

This splits up the path and makes generating reverse routes/links hard since I would have to again puzzle together the nested path elements manually.

lambdaupb avatar Apr 24 '22 13:04 lambdaupb

Can you describe your use-case with example routes ?

romain-grecourt avatar Apr 24 '22 20:04 romain-grecourt

To be consistent with http2 and WebSocket, it's better to add another task.

  • [ ] Separate HTTP/1 from WebServer (standalone module)

lilac avatar Nov 04 '23 14:11 lilac