Skip to content

Commit

Permalink
Update REST docs to reflect fully-qualified links now being the defau…
Browse files Browse the repository at this point in the history
…lt link behaviour
  • Loading branch information
paulcwarren committed Aug 12, 2020
1 parent f87e416 commit 9d42c77
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 118 deletions.
51 changes: 17 additions & 34 deletions spring-content-rest/src/main/asciidoc/rest-fullyqualifiedlinks.adoc
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
== Fully Qualified Links
By default, and where possible, Spring Content REST exports Spring Resources to shortened link URIs. These will often
match the Spring Data Rest Entity URI.
== Store Links

Given the following example:
For each Spring Resource associated with an Entity, Spring Content REST will generate a fully-qualified link and inject it into the Entity's
Spring Data REST HAL response.

Given the following domain model, Repository and Store:

====
[source, java]
Expand Down Expand Up @@ -31,7 +32,7 @@ Given the following example:
----
====

As there is only a single associated Spring Resource, Spring Content REST will generate the following URI:
Spring Content REST will inject the following link:

====
[source, java]
Expand All @@ -43,62 +44,44 @@ As there is only a single associated Spring Resource, Spring Content REST will g
"dvd" : {
...
},
"dvds" : {
"href" : "http://localhost:8080/dvds/1"
"content" : {
"href" : "http://localhost:8080/dvds/1/content"
}
}
----
====

To generate fully qualified link URIs set the following property:
Where the linkrel is named after the `@ContentId` property and the link URI is the fully-qualified URI of that content property.

====
[source, java]
----
spring.content.rest.fullyQualifiedLinks=true
----
====
=== Customizing the link relation

Or if you are not using Spring Boot, you can do the following:
Sometimes it can be useful to configure the linkrel for a content property. This is done by specifying the `linkRel` attribute on
the StoreRestResource, as follows:

====
[source, java]
----
@Configuration
class CustomContentRestMvcConfiguration {
@Bean
public ContentRestConfigurer contentRestConfigurer() {
return new ContentRestConfigurer() {
@Override
public void configure(RestConfiguration config) {
config.setFullyQualifiedLinks(true);
}
};
}
}
@StoreRestResource(linkRel="custom-content")
public interface DvdStore extends ContentStore<Dvd, UUID> {}
----
====

Spring Content REST will now generate links as follows:
This will result in the following linkrel instead:

====
[source, java]
----
"_links" : {
"_links" : {
"self" : {
...
},
"dvd" : {
...
},
"content" : {
"custom-content" : {
"href" : "http://localhost:8080/dvds/1/content"
}
}
----
====

where `content` is the extracted property name taken from the field `contentId`.
1 change: 0 additions & 1 deletion spring-content-rest/src/main/asciidoc/rest-index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ include::{spring-versions-jpa-docs}/jpaversions-rest.adoc[leveloffset=+1]
include::rest-cors.adoc[leveloffset=+1]

include::rest-baseuri.adoc[leveloffset=+1]
include::rest-linkrel.adoc[leveloffset=+1]
include::rest-fullyqualifiedlinks.adoc[leveloffset=+1]
include::rest-storeresolver.adoc[leveloffset=+1]
include::rest-putpostresolver.adoc[leveloffset=+1]
83 changes: 0 additions & 83 deletions spring-content-rest/src/main/asciidoc/rest-linkrel.adoc

This file was deleted.

0 comments on commit 9d42c77

Please sign in to comment.