Bard is a web framework that is easy to use and extend.
It is not stable now.
- Java 1.8
- Maven 3
You can just write handlers like this:
@Produces("application/json")
public class SimpleHandler extends Handler {
@GET
@Path("/add")
@Doc("Add two numbers")
public int add(
@QueryParam("a") @Required int a,
@QueryParam("b") @Required int b) {
return a + b;
}
}
For example, you can define your custom injectors like this:
@BindTo(QueryParam.class)
public class QueryParamInjector extends Injector<QueryParam> {
@Before
public void getParams() {
context.putCustom("param", annotation.value());
String param = context.getRequest().getParameter(annotation.value());
if (param == null) {
context.setInjectorVariable(null);
return;
}
TypeParser parser = TypeParser.newBuilder().build();
context.setInjectorVariable(parser.parse(param, context.getInjectorVariableType()));
}
@Override
public void generateDoc() {
docParameter.name = annotation.value();
docParameter.type = context.getInjectorVariableType();
docParameter.belongs = "url";
}
}
No more code needed, once your handler is written, the API documents is right there for you. The users could also try the APIs in the web UI. Isn't that cool?
See a live demo.
Just with one command mvn package bard:standalone
, this framework will generate a self contained directory
which is ready to deploy. It contains directory conf
to store config files, bin
to store start up and shut
down scripts, lib
to store library JARs and log
to store all the logs for you.
Just run bin/server.sh start | restart | stop
, you can control your server.
If you want to build a WAR package in order to run in a servlet container, that is easy, too.
Just run mvn package bard:war
, then you will get a WAR package.
See the detailed documents.
It is better to manage the dependency with maven:
<dependency>
<groupId>com.bardframework</groupId>
<artifactId>bard-core</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>com.bardframework</groupId>
<artifactId>bard-basic</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>com.bardframework</groupId>
<artifactId>bard-util</artifactId>
<version>0.1.0</version>
</dependency>
This framework is licensed under Apache 2.0.