Ok, based upon the information provided so far, I have something working that I think makes sense. I'm definitely looking for someone to validate my theories so far.
The goal was to be able to implement additional custom methods to the methods that SDR already provides. This is because I need to implement additional logic that cannot be expressed as simple Spring Data Repository query methods (the findByXXX methods). In this case, I'm looking to query other data sources, like Solr, as well as provide custom manipulation of the data before its returned.
I have implemented a Controller based upon what @oliver suggested, as follows:
@BasePathAwareController
@RequestMapping(value = "/persons/search")
public class PersonController implements ResourceProcessor<RepositorySearchesResource>, ResourceAssembler<Person, Resource<Person>> {
@Autowired
private PersonRepository repository;
@Autowired
private EntityLinks entityLinks;
@RequestMapping(value = "/lookup", method = RequestMethod.GET)
public ResponseEntity<Resource<Person>> lookup(@RequestParam("name") String name)
{
try
{
Resource<Person> resource = toResource(repository.lookup(name));
return new ResponseEntity<Resource<Person>>(resource, HttpStatus.OK);
}
catch (PersonNotFoundException nfe)
{
return new ResponseEntity<Resource<Person>>(HttpStatus.OK);
}
}
@Override
public RepositorySearchesResource process(RepositorySearchesResource resource) {
LinkBuilder lb = entityLinks.linkFor(Person.class, "name");
resource.add(new Link(lb.toString() + "/search/lookup{?name}", "lookup"));
return resource;
}
@Override
public Resource<Person> toResource(Person person) {
Resource<IpMaster> resource = new Resource<Person>(person);
return resource;
}
This produces a "lookup" method that is considered a template and is listed when you do a query on /persons/search
, along with the other search methods defined in the Repository
. It doesn't use the PersistentEntityResourceAssembler
that was suggested. I think I would rather use that, but then I'm a bit confused as to how to get it injected, and what the comment about the filed bug means.
users
alongsidegetUsers
to additionally support aStream
return type. But even if you name your methodfindByX
it doesn't mean that you have to name the resourcefindByX
too. You can havefindByName
while exposing it as/users/search/foo
. You are arguing that a renowned framework supporting the highest level of REST is not RESTful. Think about it. Btw: There are experts who would discourage?q=name:somename
. – Coverup?q=name:somename
, why do you think is discouraged? I recon that the HTTP query can be used to pass filtering parameters, but I prefer not to mix the filter query string with other params (e.g. paging, etc..). – Riband