jooby-project / jooby

The modular web framework for Java and Kotlin
https://jooby.io
Apache License 2.0
1.71k stars 197 forks source link

Extending routes #365

Closed gdrte closed 8 years ago

gdrte commented 8 years ago

Jooby doesn't support extending routes. The usage is, define some common API(CRUD) in Abstract route and extend this router to add additional APIs. What exactly I mean is as follows. `@RestController abstract public class AbstractController { /* * List the Models * @return List, a list of Models. / @RequestMapping(method = RequestMethod.GET) public List list() { return dao.find().asList(); } / * Get the Model given by an ID * @return Model. */ @RequestMapping(method = RequestMethod.GET,value="/{id}") public Model findOne(@PathVariable final String id) { return dao.get(new ObjectId(id)); }

/**
 * Create a new Model
 *
 * @param model Model The Model object
 * @return Model, On success returns saved Model with generated id.
 */
@RequestMapping(method = RequestMethod.POST)
public Model create(@RequestBody Model model) {
    dao.save(model);
    return model;
}

} @RestController @RequestMapping("/api/user") public class UserController extends AbstractController {

@Autowired
public UserController(DAO dao) {
    super(dao);
}

@RequestMapping(method= RequestMethod.POST, value = "/login")
void login(){

}
@RequestMapping(method= RequestMethod.POST, value="/logout")
void logout(){

}

}` screen shot 2016-04-25 at 3 13 40 pm

danielfireman commented 8 years ago

Sorry for chiming in late. As far as I could understand, the main goal is to have an easier/faster way to implement CRUDs, right?

If the answer is yes, maybe we could get away without inheritance (I could see some complications with this implementation, in particular, regarding consistency checks between implementation of the super class and sub classes). @jknack @gdrte have you guys thought of using @Crud Annotation? Something like:

@CrudController(methods={CREATE, READ, UPDATE, DELETE}, dao = UserDao.class) public class UserController { ,,, } Then we would have some processor that implements CRUD in a very simple way.

We could use Guice to create a new instance of UserDao.

Any thoughts?

gdrte commented 8 years ago

@danielfireman I am afraid, the implementation will be complex. How should it support, if I want all my CRUDs are non-blocking?

jknack commented 8 years ago

Agreed with @gdrte.

@danielfireman what do you mean with:

I could see some complications with this implementation, in particular, regarding consistency checks between implementation of the super class and sub classes

can you provide an example?