Created
October 12, 2017 12:36
-
-
Save adamw/6248904a39eb3fedb89d3c9a1752ba10 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hello.java | |
public class Hello { | |
public String helloWorld() { | |
return "Hello World"; | |
} | |
} | |
// HelloEndpoints.java | |
public class HelloEndpoints { | |
private Endpoint helloWorldEndpoint(Hello hello) { | |
return Endpoint | |
.withPath("/hello") | |
.method(GET) | |
.produces(MediaType.TEXT_PLAIN) | |
.invoke(hello::helloWorld); | |
} | |
public List<Endpoint> endpoints(Hello hello) { | |
return Arrays.asList(helloWorldEndpoint(hello), ...); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Btw. as for the specific example with extracting path parameters, I think a Java API could be sth like this:
Here, the first invocation of
withPathSegment
would be onEndpoint0
, and yield anEndpoint1<String>
(an endpoint, which requires a single string parameter - in this case, read from the path, but could be read from the query as well).The second would be on
Endpoint1<String>
and yield anEndpoint2<String, Integer>
, etc. Then, theinvoke
method can be properly typed to expect a method reference with the right signature.That's of course just a sketch, and would require the library author to define a number of
EndpointN
classes (or maybe auto-generate them?). In Scala, you have have a singleEndpoint
class which can accumulate the input/output parameters with some combinators (again, see Tapir for details).