Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleUriRouter to KaryonRestModule ? #225

Open
victuxbb opened this issue May 2, 2015 · 4 comments
Open

SimpleUriRouter to KaryonRestModule ? #225

victuxbb opened this issue May 2, 2015 · 4 comments

Comments

@victuxbb
Copy link

victuxbb commented May 2, 2015

Hi! I would like to discuss about the question that I made here
https://groups.google.com/forum/?fromgroups#!topic/karyon-users/k-nrZ9V2OoQ

Currently I working on a company (Schibsted) that gives me time to collaborate (or try it) with your amazing NetflixOSS ecosystem :)

Well, I first approach that I'm thinking could be...

1- A config file were you put the configuration about REST resources, for example:

campaigns:
  type:     rest
  resource: company.package.to.CampaignsResource

2- When Karyon starts, it reads this file and then by "reflection" we can read all classes on it and by a convention of methods, build routes that matches this methods, for example:
CampaignsResource.java

public Observable<Void> getCampaignsResource(String id) {
        //Do whatever...
    }

public Observable<Void> putCampaignsResource(String id) {
        //Do whatever...
    }

public Observable<Void> getCampaignsUsersResource(String id) {
        //Do whatever...
    }

Reading this methods you can extract by convention this routes:

GET /campaigns/{id}
PUT /campaigns/{id}
GET /campaigns/{id}/users

All this development would be a module that you can load in the bootstrap application

What do you think? I'm completly open to changes or new ideas :)

Thanks!

@NiteshKant
Copy link
Contributor

How would you put this configuration file based approach in contrast to annotations based approach like what Jersey (jax-rs) uses? What pros & cons do you see?

@victuxbb
Copy link
Author

Well...this is a mythical question, annotations vs configuration :)
Personally I would summarize it in :

Annotations have become more harmful than helpful these days.
We should get back to pojos and focus on keeping our code as clutterless 
and framework-agnostic as possible to make it more readable and reuseable. 
Don’t let frameworks dictate your codebases, since they should be exchangable tools.
Beware of what a class should know, and what not. Some annotations are useful, 
most aren’t.
http://www.javacodegeeks.com/2014/01/an-annotation-nightmare.html

I think that a good framework must provide the option to choose how you want to work, for example, play framework, gives you the possibility to choose between annotations in your controllers or have a routing file with all routes:

Annotations:
https://www.playframework.com/modules/router-1.1/home

Configuration:
https://www.playframework.com/documentation/2.0/JavaRouting

Another good example for me is in the library GSON from google, you can configure the GSONBuilder to use annotations or not.

GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()

In conclusion I think would be a good point give support both options.

How do you see?

:)

@victuxbb
Copy link
Author

victuxbb commented Jun 8, 2015

Hi @NiteshKant, I made a first draft version using annotations:

https://github.com/scm-spain/karyon-rest-router

I'll keep adding features and anything that could be useful.

@NiteshKant
Copy link
Contributor

@victuxbb great! Let me know when you are ready for a PR and I can review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants