Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTful Strings matcher in Java

Tags:

java

rest

url

I'm looking for a Java library that evaluates REST-style URLs. Something like:

public Result evaluate(String url, String pattern);

The pattern would be something like:

/users/{userId}/photos/{photoId}.html

The result must include:

  • indication if the url matches pattern
  • the actual values of the url variables {userId} and {photoId}

Can anyone help, please?

like image 836
Charles Abreu Avatar asked Aug 24 '10 23:08

Charles Abreu


2 Answers

By "evaluate", do you mean some kind of unification or pattern matching by which the url string is matched against the pattern string, mapping the placeholders in the pattern to the corresponding substrings in the URL?

If so, the Restlet library's Template class may suffice. In particular, look at Template#parse(String, Map<String, Object>). That looks close to fitting your needs, though the documentation is a little vague as to what constitutes the input and output.

like image 75
seh Avatar answered Oct 23 '22 09:10

seh


You might already know about this, but JBoss RestEasy http://jboss.org/resteasy project handles such cases and should have classes to deal with such cases. I believe its open source and therefore you can see if its helpful

like image 32
Fazal Avatar answered Oct 23 '22 09:10

Fazal