I'm faced with a scenario where the custom @RepositoryRestResource interface-method is involved by the wrong HTTP-Method. For example:
@RepositoryRestResource(path = "matches", collectionResourceRel = "matches")
public interface MatchRepo extends Neo4jRepository<Match, Long> {
Collection<Match> findAllByCodeName(@Param("codeName") String codeName);
@Transactional
Long deleteAllByCodeName(@Param("codeName") String codeName);
}
Request:
curl -i -X GET 'http://localhost:8003/spring-data/api/v1/matches/search/findAllByCodeName?codeName=Test-CodeName-1'
Note the above GET HTTP-Method. This is expected, & i'm happy with the Response:
HTTP/1.1 200
Content-Type: application/hal+json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 20 Nov 2018 15:32:49 GMT
{
"_embedded" : {
"matches" : [ {
"id" : "1",
"codeName" : "Test-CodeName-1",
"round" : 1,
"me" : "ROCK",
"pc" : "ROCK",
"result" : "D",
"timestamp" : "Nov 20, 2018, 05:32:27 AM",
"lastUpdated" : "Nov 20, 2018, 05:32:27 AM",
"created" : "Nov 20, 2018, 05:32:27 AM",
"_links" : {
"self" : {
"href" : "http://localhost:8003/spring-data/api/v1/matches/22"
},
"match" : {
"href" : "http://localhost:8003/spring-data/api/v1/matches/22"
}
}
} ]
},
"_links" : {
"self" : {
"href" : "http://localhost:8003/spring-data/api/v1/matches/search/findAllByCodeName?codeName=Test-CodeName-1"
}
}
}%
This is what appears on the Intelli-J Console-Mappings:
http://localhost:8003/spring-data/api/v1/{repository}/search
& I implemented the request as indicated in the mappings, as shown below. But the problem becomes evident when I am deleting a resource with a GET HTTP-Method as shown below:
Request:
curl -i -X GET 'http://localhost:8003/spring-data/api/v1/matches/search/deleteAllByCodeName?codeName=Test-CodeName-1'
Response:
HTTP/1.1 200
Content-Type: application/hal+json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 20 Nov 2018 15:51:33 GMT
{
"10":
}
I need to find a way to make my custom deleteAllByCodeName(@Param) interface-method from the MatchRepo class to execute with the correct HTTP-Method. Must use DELETE HTTP-Method & not the GET HTTP-Method and adhere to the REST-API Design Principles.