Reputation: 3715
Here is project/Spring Data Rest version.
// gradle
springBootVersion = '2.4.2'
springDependencyManagement = '1.0.10.RELEASE'
Here is my code:
@RepositoryRestResource(collectionResourceRel = "address", path = "address")
public interface AddressRepository extends PagingAndSortingRepository<Address, Long> {
@Transactional
@RestResource(description = @Description("delete all addresses based on the given city"))
Long deleteAllByCity(String city);
}
address/search
doesn't work
{
"_links" : {
"deleteAllByCity" : {
"href" : "http://localhost:8080/api/v1/address/search/deleteAllByCity{?city}",
"templated" : true
},
"self" : {
"href" : "http://localhost:8080/api/v1/address/search"
}
}
}
/profile/address
doesn't work
...
{
"name": "deleteAllByCity",
"type": "SAFE",
"descriptor": [
{
"name": "city",
"type": "SEMANTIC"
}
]
}
...
How can I add description into search and profile?
Upvotes: 0
Views: 141
Reputation: 2419
According to documentation, RestResource.description
is the description of the collection resource, so it is not meant to describe a method, even though @RestResource
can be put on method.
To add humen-readable string to a link in the response of /address/search
, create a file src/main/resources/rest-messages.properties
, add a line _links.deleteAllByCity.title=delete all addresses based on the given city
. Then the /address/search
response JSON should become
{
"_links" : {
"deleteAllByCity" : {
"href" : "http://localhost:8080/api/v1/address/search/deleteAllByCity{?city}",
"templated" : true,
"title" : "delete all addresses based on the given city"
},
"self" : {
"href" : "http://localhost:8080/api/v1/address/search"
}
}
}
https://docs.spring.io/spring-hateoas/docs/current/reference/html/#mediatypes.hal.i18n
Upvotes: 1