Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data REST - collectionResourceRel vs path

I'm using Spring Data REST. RepositoryRestResource annotation has two different fields: path and collectionResourceRel. What's the difference between those two? I can't figure this out by reading the documentation.

path is described:

The path segment under which this resource is to be exported.

and collectionResourceRel is described:

The rel value to use when generating links to the collection resource.

In all code examples I've seen these two properties where the same. Is there any case when they differ? And what is the actual difference between them?

like image 701
k13i Avatar asked May 18 '18 12:05

k13i


1 Answers

For example, for entity User the default values will be:

path = users

itemResourceRel = user

collectionResourceRel = users

Example:

GET /users (path: users)

"_links": { 
        "self": {
            "href": "http://localhost:8080/api/users"
        },
        "users": {  <-- collectionResourceRel
            "href": "http://localhost:8080/api/users"
        }
    }

GET /users/1 (path: users)

"_links": {
        "self": {
            "href": "http://localhost:8080/api/users/1"
        },
        "user": { <-- itemResourceRel
            "href": "http://localhost:8080/api/users/1"
        }
    }
like image 139
Cepr0 Avatar answered Sep 21 '22 13:09

Cepr0