JoyRest is a lightweight and convenient tool for creating REST services
by a concise way.
The main intention is to provide framework which is simply extensible for different types of DI and servers.
JoyRest is purely developed using Java programming language 8 and with lambdas
.
Thank to this technology the framework is able to provide very clear API which allows you to defined your
endpoints through a functional way
.
Maybe someone may find strict declaring of Request/Response types as a verbose and annoying activity, but this is the biggest advantage of JoyRest. Since this strict defining types allows to JoyRest resolve Writes/Readers during an application bootstrapping and not during a Request processing. This is a trade-off between an additional written code and a performance impact.
JoyRest has chose the better performance !!
In addition the strongly-typed nature of JoyRest allows us to use some Automatic Documentation Generator
because all information about routes are available immediately after the creation of dependency injection context.
Don't forget to try out JoyRest-Maven-Plugin which provides
extensible functionality of generation documentation.
There are three ways to define a body of the given route. Even if it's the lambda-based approach
of defining routes the most favourite concept, it also worth mentioning other two approaches. For the sake of simplicity
and conciseness my favourite is Lambda! Try it out or look at the
Examples on GitHub
JoyRest prefers the way without or at least eliminate a number of annotations used during the declaring and bootstrapping the application. Annotations can be sometimes very confusing and make harder following debugging and understanding of the code underneath.
public class JokeController extends TypedControllerConfiguration {
@Inject
private JokeService service;
@Override
protected void configure() {
setControllerPath("jokes");
post((req, resp) -> {
Joke savedJoke = service.save(req.getEntity());
resp.entity(singletonList(savedJoke))
.status(CREATED);
}, Req(Joke.class), RespList(Joke.class))
.consumes(JSON).produces(JSON);
get((req, resp) -> {
List jokes = service.getAll();
resp.entity(jokes);
}, RespList(Joke.class)).produces(JSON, XML);
get("{id}", (req, resp) -> {
Joke joke = service.get(req.getPathParam("id"));
resp.entity(joke);
}, Resp(Joke.class)).produces(JSON, XML);
}
}