Controller routing definition in configuration file.#15
Controller routing definition in configuration file.#15fmeurisse wants to merge 1 commit intoybonnel:masterfrom fmeurisse:master
Conversation
|
I don't like config by file (it's not compile time, and in case of refactoring it's hell). But your pull request gave me an idea, use annotation : public static class Controller {
@Jsonp(callback = "CALLBACK", path = "/jsonp", resultType = String.class)
@Get(path = "/resource", resultType = String.class)
public static String helloWorld() {
return "Hello World";
}
@Get(path = "/resource/:name", resultType = String.class)
public static String helloName(@RouteParam("name") String name) throws HttpErrorException {
if (name.equals("notfound")) {
throw new HttpErrorException(404);
}
return "Hello " + name;
}
@Post(path = "/resource", paramType = String.class, resultType = String.class)
@Put(path = "/resource/put", paramType = String.class, resultType = String.class)
public static String helloPost(String name) {
return "Hello " + name;
}
@Get(path = "/othercode", resultType = String.class)
public static Response<String> iAmATeaPot() {
return new Response<>("I m a teapot", 418);
}
@Delete(path = "/resource/delete", resultType = String.class)
public static String delete() {
return "deleted";
}
}And in the main : setAnnotatedClasses(Controller.class);Maybe also an annotation for resource, something like : @Resource(path = "/member", type = Member.class)What do you think? |
|
I will try to implement that. 2013/9/17 Yan Bonnel notifications@github.com
|
|
I've created the branch "annotation" with my idea of annotations. Test to fix : AnnotationIntegrationTest I did not create the annotation for Resource, because i'm not sure how to do that (must extend RestResource, so there is a constructor to call, ...). |
This commit add the possibility to define routing in a configuration file. Each line of the configuration file defines a line with the following format:
[HttpMethod] [paramType] [routePath] [controller static method]\n