Files
Spring Operator e0ef48eb78 #474 - URL Cleanup.
This commit updates URLs to prefer the https protocol. Redirects are not followed to avoid accidentally expanding intentionally shortened URLs (i.e. if using a URL shortener).

# Fixed URLs

## Fixed Success
These URLs were switched to an https URL with a 2xx status. While the status was successful, your review is still recommended.

* [ ] http://www.apache.org/licenses/ with 1 occurrences migrated to:
  https://www.apache.org/licenses/ ([https](https://www.apache.org/licenses/) result 200).
* [ ] http://www.apache.org/licenses/LICENSE-2.0 with 320 occurrences migrated to:
  https://www.apache.org/licenses/LICENSE-2.0 ([https](https://www.apache.org/licenses/LICENSE-2.0) result 200).
2019-03-22 08:00:34 +01:00
..
2019-03-22 08:00:34 +01:00
2019-03-20 10:11:16 -05:00

= Spring Data REST - Headers example

This example shows how Spring Data REST auto-populates response headers for item resources and considers these values when conditional `GET` requests are used

== Auto-populated headers

If entities use optimistic locking (usually by demarcating a particular property as version property using a store-specific annotation), Spring Data REST will use the value stored in that property to populate the `ETag` header for `GET` and `HEAD` requests to the item resource.

If http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#auditing[Spring Data's auditing capabilities] are activated (using `@EnableJpaAuditing` in this case), the `Last-Modified` header is populated with the value of the last-modified property. See the `Customer` domain class for how to mark those.

== Conditional GET requests

The response headers can be used to issue conditional GET requests to save bandwidth in case the resource hasn't changed on the server:

.Conditional GET using If-Modified-Since
====
[source,bash]
----
$ curl http://localhost:8080/customers/1 -i -H "If-Modified-Since: Wed, 08 Apr 2015 17:24:20 GMT"
----

[source,http]
----
HTTP/1.1 304 Not Modified
----
====

.Conditional GET using If-None-Match
====
[source,bash]
----
$ curl http://localhost:8080/customers/1 -i -H "If-None-Match: 0"
----

[source,http]
----
HTTP/1.1 304 Not Modified
----
====

== Cross-Origin Resource Sharing

Client-side JavaScript that issue cross-origin requests require the server to evaluate cross-origin requests and respond appropriately.

.Cross-Origin Request
====
[source,bash]
----
$ curl 'http://localhost:8080/customers/' -i -H 'Origin: http://localhost'
----

[source,http]
----
HTTP/1.1 200 OK
Access-Control-Allow-Origin: http://localhost
Vary: Origin
Access-Control-Allow-Credentials: true
----
====

== Spring RESTDocs

The sample uses https://github.com/wilkinsona/spring-restdocs[Spring RESTDocs] to document the HTTP interaction implemented using the test cases. See `WebIntegrationTests.setUp()` for general setup and the individual test methods with their usage of `….andDo(document(…))`.