Skip to content

hilla: add example usage of EndpointExposed #4251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions articles/hilla/lit/guides/endpoints.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,41 @@ include::{root}{root-fix}/src/main/java/com/vaadin/demo/fusion/accessingbackend/
The only difference is that `@BrowserCallable` doesn't support the `value` attribute. This means the endpoint name is always the same as the class name.


=== Extending Other Classes

Endpoints are standard Java classes and can extend other classes and implement interfaces. However, to prevent unintentional exposure, methods inherited from superclasses aren't generated by default.

To expose methods from a superclass, use the `@EndpointExposed` annotation.

The following example demonstrates that only methods from the endpoint itself and annotated superclasses are generated. The same principle applies to interfaces.

[source,java]
----
@EndpointExposed
public class ExposedClass {
public String fromExposedClass() { // <1>
return "Hello from ExposedClass";
}
}

public class NonExposedClass extends ExposedClass {
public String fromNonExposedClass() { // <2>
return "Hello from NonExposedClass";
}
}

@Endpoint
public class EndpointClass extends NonExposedClass {
public String fromEndpointClass() { // <3>
return "Hello from EndpointClass";
}
}
----
<1> This method is generated in `EndpointClass`.
<2> This method is not generated, as its class is not annotated.
<3> This method is generated, as it's in the endpoint class.


== Modules Generated from Hilla Endpoints

Hilla generates a TypeScript module for every Hilla endpoint on the backend. Each such module exports all of the methods in the endpoint.
Expand Down