[undertow-dev] REST routing

Stuart Douglas sdouglas at redhat.com
Mon Apr 14 20:38:19 EDT 2014



Bill O'Neil wrote:
> I was curious what the best practices would be for url routing with many
> endpoints.
>
> For example
>
> POST /user/
> GET /user/{userId}
> GET /document/{documentId} ContentType=appliction/json (only respond
> when json is requested)
>
> What would be the best option for this? I was able to achieve most of
> what i wanted using the PredicatesHandler class. Is this a good choice?

That will work fine, although there are more efficient ways to do this.
I think this will actually be a fairly common use case, so I have added 
a handler to handle this:

https://github.com/undertow-io/undertow/commit/04385f29996673658bce3c131de4e0a32241e78e#diff-3 


Basically it matches requests based on a combination of method, path 
template and predicate, and will be considerably more efficient that 
testing a list of predicates.

Stuart



>
> This would build a List of PredicatedHandlers as well as the fall
> through handler which I would use as a 404. I got an example working
> using the text predicate format
>
> method[GET] and path-template[value=\"/user/{userId}\"]
>
>
> Is this a good approach or are there better recommendations?
>
>
> Thanks,
>
> Bill
>
> _______________________________________________
> undertow-dev mailing list
> undertow-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/undertow-dev


More information about the undertow-dev mailing list