it('deletes the first order using the delete action', () => {
provider
+ .uponReceiving("get root")
+ .withRequest({
+ path: "/",
+ })
+ .willRespondWith({
+ status: 200,
+ headers: {
+ 'Content-Type': 'application/vnd.siren+json'
+ },
+ body: {
+ class:[ "representation"],
+ links:[{"rel":["orders"], "href": url("http://localhost:9000", ["orders"]) }]
+ }
+ })
.uponReceiving("get all orders")
.withRequest({
path: "/orders",
async function deleteFirstOrder(url) {
const client = new Client(url)
- const ordersResource = client.go('/orders')
+ const ordersResource = await client.follow('orders')
const ordersResp = await ordersResource.get()
const firstOrder = ordersResp.getEmbedded()[0]
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.afford;
@RestController
@ExposesResourceFor(Order.class)
+@RequestMapping("/orders")
public class OrderController {
@GetMapping("/orders")
--- /dev/null
+package io.pactflow.example.sirenprovider.controllers;
+
+import io.pactflow.example.sirenprovider.models.Order;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.hateoas.Link;
+import org.springframework.hateoas.RepresentationModel;
+import org.springframework.hateoas.server.EntityLinks;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class RootController {
+
+ static class Root extends RepresentationModel<Root> {}
+
+ @Autowired
+ private EntityLinks entityLinks;
+
+ @GetMapping("/")
+ public ResponseEntity<RepresentationModel<?>> orders() {
+ Link link = entityLinks.linkToCollectionResource(Order.class).withRel("orders");
+ return ResponseEntity.ok().body(new Root().add(link));
+ }
+}