Skip to content

gregturn/spring-data-rest-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to run

You can choose to the Spring Boot CLi version of this sample:

  1. Install Spring Boot CLI

  2. spring jar app.jar sample.groovy && java -jar app.jar

  3. In another shell, use curl to interrogate the service

Or you can check out the Spring Boot Java-based version:

  1. mvn clean spring-boot:run

Either of these options will let you poke around with a simple example of Spring Data REST.

What you’ll see

$ curl localhost:8080/persons

It will yield:

{
  "_embedded" : {
    "persons" : [ {
      "firstName" : "Frodo",
      "lastName" : "Baggins",
      "addresses" : [ {
        "street" : "Bag End",
        "state" : "The Shire",
        "country" : "Middle Earth"
      }, {
        "street" : "The Undying Lands",
        "state" : "Ships",
        "country" : "Elven Lands"
      } ],
      "_links" : {
        "self" : {
          "href" : "http://localhost:8080/persons/1{?projection}",
          "templated" : true
        },
        "addresses" : {
          "href" : "http://localhost:8080/persons/1/addresses"
        }
      }
    } ]
  }
}

This shows an excerpt projection being applied. It causes the address resources to get inlined. You can still navigate to that collection.

$ curl localhost:8080/persons/1/addresses

This will show links for each address:

{
  "_embedded" : {
    "addresses" : [ {
      "street" : "Bag End",
      "state" : "The Shire",
      "country" : "Middle Earth",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8080/addresses/1"
        }
      }
    }, {
      "street" : "The Undying Lands",
      "state" : "Ships",
      "country" : "Elven Lands",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8080/addresses/2"
        }
      }
    } ]
  }
}

About

Spring Boot CLI app with Spring Data REST

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published