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

Allow specification of Accept-Type by appending a registered suffix to the request path #185

Merged
merged 2 commits into from
Jun 28, 2015

Conversation

gitblit
Copy link
Collaborator

@gitblit gitblit commented Jun 27, 2015

This PR allows specification of the Accept-Type on the Request path.

http://localhost:8338/contact
http://localhost:8338/contact.json
http://localhost:8338/contact.xml
http://localhost:8338/contact.yaml

The path suffix is matched against the trailing pseudo-suffix of the registered ContentTypeEngine.

e.g. application/json = json
e.g. application/x-yaml = yaml

GET("/contact(\\.(json|xml|yaml))?", new RouteHandler() {
    @Override
     public void handle(RouteContext routeContext) {
        Contact contact = new Contact()
            .setId(12345)
            .setName("John")
            .setPhone("0733434435")
            .setAddress("Sunflower Street, No. 6");
        routeContext.xml().negotiateContentType().send(contact);
    }
});

Aside from the verbose route path specification, the behavior is transparent to the end-user. I have an idea on how to make this suffix support easier to use for route registration but it will require some rearchitecting to achieve.

@gitblit
Copy link
Collaborator Author

gitblit commented Jun 27, 2015

@decebals I happen to think this change is particularly useful - although the route registration could stand improvement. More on that if we can get this merged.

@decebals
Copy link
Member

I think that this feature can be useful for some people.

* @return null or the first matching content type engine
*/
public ContentTypeEngine getContentTypeEngine(String contentType) {
if (StringUtils.isNullOrEmpty(contentType)) {
public ContentTypeEngine getContentTypeEngine(String contentTypeOrSuffix) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From implementation I see a permutation: suffixOrContentType instead of contentTypeOrSuffix. Am I wrong?

decebals added a commit that referenced this pull request Jun 28, 2015
Allow specification of Accept-Type by appending a registered suffix to the request path
@decebals decebals merged commit 9a613ea into master Jun 28, 2015
@decebals
Copy link
Member

Thanks

@gitblit gitblit deleted the accept_type_suffix branch June 28, 2015 14:31
@gitblit
Copy link
Collaborator Author

gitblit commented Jun 28, 2015

Cool. Thanks for the merge.

@decebals
Copy link
Member

decebals commented Jul 2, 2015

@gitblit Can you update doc with this cool feature, please?

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

Successfully merging this pull request may close these issues.

None yet

2 participants