gxshub / rest-services-with-spring-v2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

REST Services with Spring V2

This exemplar project includes multiple domain classes and a relationship between those classes.

Demonstration: Sample REST Requests

  • Request 1.

In Windows CMD,

curl -X POST -H "Content-Type:application/json" -d "{\"name\":\"My Library\"}" http://localhost:8081/libraries

In MacOS/Linux,

curl -X POST -H "Content-Type:application/json" -d '{"name":"My Library"}' http://localhost:8081/libraries

which returns

{"id":1,"name":"My Library"}
  • Request 2. In Windows CMD,
curl -X POST -H "Content-Type:application/json" -d "{\"location\":\"Main Street nr 5\"}" http://localhost:8081/addresses

In MacOS/Linux,

curl -X POST -H "Content-Type:application/json" -d '{"location":"Main Street nr 5"}' http://localhost:8081/addresses

which returns

{"id":2,"location":"Main Street nr 5","library":null}
  • Request 3.
curl -i -X PUT http://localhost:8081/libraries/1/address/2

which returns

{"id":1,"name":"My Library"}
  • Request 4.
curl -X GET http://localhost:8081/addresses/2

which returns

{"id":2,"location":"Main Street nr 5","library":{"id":1,"name":"My Library"}}

Note that the value of "library" has been updated from null to {"id":1,"name":"My Library"}.

About


Languages

Language:Java 100.0%