Hypermedia API’s

591 views
508 views

Published on

Victor Welling - Coolblue – Hypermedia API’s

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
591
On SlideShare
0
From Embeds
0
Number of Embeds
56
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Hypermedia API’s

  1. 1. { "_links" : { "self" : { "href" : "/products/32154" }, "profile" : { "href" : "http://example.com/schema/product" }, "add-to-shopping-cart" : { "href" : "/shopping-cart/{shoppingCartId}/lines", "templated" : true } }, "productId" : 32154, "name" : "Sungsam iClone IX", "brand" : "Sungsam", "availability" : "on stock", "price" : 699.95}
  2. 2. <resource href="/products/32154"> <link rel="profile" href="http://example.com/schema/product"/> <link rel="add-to-shopping-cart“ href="/shopping-cart/{shoppingCartId}/lines“ templated="true"/> <productId>32154</product> <name>Sungsam iClone IX</name> <brand>Sungsam</brand> <availability>on stock</availability> <price>699.95</price></resource>
  3. 3. { "_links" : { "self" : { "href" : "/shopping-cart/794" }, "profile" : { "href" : "http://example.com/schema/shopping-cart" }, "order" : { "href" : "/orders" } }, "_embedded" : { "line" : [{ "_links" : { "self" : { "href" : "/shopping-cart/794/lines/1" }, "product" : { "href" : "/product/32154" } }, "productId" : 32154, "description" : "Sungsam iClone IX", "quantity" : 1, "price" : 699.95 }] }, "priceTotal" : 699.95}
  4. 4. GET / HTTP/1.1HTTP/1.1 200 OK{ "_links" : { "self" : { "href" : "/" }, "profile" : { "href" : "http://example.com/schema/index" }, "orders" : { "href" : "/orders" }, "products" : { "href" : "/products{?productId,name,brand}", "templated" : true }, "shopping-carts" : { "href" : "/shopping-carts" }, }}
  5. 5. GET /products?brand=Sungsam HTTP/1.1HTTP/1.1 200 OK{ "_links" : { [...] "products" : { "href" : "/products{?productId,name,brand} ", "templated" : true } }, "_embedded" : { "product" : [{ "_links" : { "self" : { "href" : "/products/32154" } }, "productId" : 32154, "name" : "Sungsam iClone IX" }] }}
  6. 6. GET /products/32154 HTTP/1.1HTTP/1.1 200 OK{ "_links" : { "self" : { "href" : "/products/32154" }, "profile" : { "href" : "http://example.com/schema/product" }, "add-to-shopping-cart" : { "href" : "/shopping-cart/{shoppingCartId}/lines", "templated" : true } }, "productId" : 32154, "name" : "Sungsam iClone IX", "brand" : "Sungsam", "availability" : "on stock", "price" : 699.95}
  7. 7. POST /shopping-cart/794/lines HTTP/1.1{ "product" : { "href" : "/products/32154" }, "quantity" : 1}[...]
  8. 8. HTTP/1.1 201 CreatedLocation: /shopping-cart/794/lines/1{ "_links" : { "self" : { "href" : "/shopping-cart/794/lines/1" }, "profile" : { "href" : "http://example.com/schema/shopping-cart/line" }, "shopping-cart" : { "href" : "/shopping-cart/794" }, "product" : { "href" : "/product/32154" } }, "productId" : 32154, "description" : "Sungsam iClone IX", "quantity" : 1, "price" : 699.95}
  9. 9. DELETE /shopping-cart/794/lines/1 HTTP/1.1HTTP/1.1 204 No Content
  10. 10. GET /shopping-cart/794 HTTP/1.1HTTP/1.1 200 OK{ "_links" : { [...] "lines" : { "href" : "/lines" }, "order" : { "href" : "/orders" } }, "_embedded" : { "line" : [{ "_links" : { "self" : { "href" : "/shopping-cart/794/lines/1" } }, [...] }] }, "priceTotal" : 699.95}
  11. 11. POST /orders HTTP/1.1{ "shoppingCart" : { "href" : "/shopping-cart/794" }}
  12. 12. HTTP/1.1 201 CreatedLocation: /orders/543{ "_links" : { [...] }, "_embedded" : { "line" : [{ "_links" : { "self" : { "href" : "/orders/543/lines/1" } }, [...] }], "payment" : [] }, "priceTotal" : 699.95, "address" : null, "customer" : null, "status" : "unprocessed", "error" : "Missing or invalid information."}
  13. 13. PUT /orders/543 HTTP/1.1{ "address" : { "street" : "Samplelane", "houseNumber" : "1337", "city" : "Demotown" }, "customer" : { "name" : "John Doe", "email" : "john@doe.com" }}
  14. 14. HTTP/1.1 200 OK{ "_links" : { [...] "payment" : { "href" : "/orders/543/payments" } }, [...] "address" : { "street" : "Samplelane", "houseNumber" : "1337", "city" : "Demotown" }, "customer" : { "name" : "John Doe", "email" : "john@doe.com" }, "status" : "unprocessed", "error" : "Missing payment."}
  15. 15. POST /orders/543/payments HTTP/1.1{ "amount" : 699.95, "type" : "creditCard", "issuer" : "Visa"}
  16. 16. HTTP/1.1 201 CreatedLocation: /orders/543/payments/1{ "_links" : { "self" : { "href" : "/orders/543/payments/1" }, "profile" : { "href" : "http://example.com/schema/payment" }, "payment" : { "href" : "/orders/543/payments" } "order" : { "href" : "/orders/543" } }, "amount" : 699.95, "type" : "creditCard", "issuer" : "Visa", "cardHolder" : "", "number" : "", "cvc" : "", "expirationDate" : "", "status" : "unprocessed", "error" : "Missing or invalid information."}
  17. 17. PUT /orders/543/payments/1 HTTP/1.1{ "cardHolder" : "J. Doe", "number" : "4111111111111111", "cvc" : "123", "expirationDate" : "2020-01"}
  18. 18. HTTP/1.1 200 OK{ "_links" : { "self" : { "href" : "/orders/543/payments/1" }, "profile" : { "href" : "http://example.com/schema/payment" }, "payment" : { "href" : "/orders/543/payments" } "order" : { "href" : "/orders/543" } }, "amount" : 699.95, "type" : "creditCard", "issuer" : "Visa", "cardHolder" : "J. Doe", "number" : "************1111", "cvc" : "***", "expirationDate" : "2020-01" "status" : "processed", "error" : ""}
  19. 19. GET /orders/543 HTTP/1.1HTTP/1.1 200 OK{ [...] "_embedded" : { [...] "payment" : [{ "_links" : { "self" : { "href" : "/orders/543/payments/1" }, "amount" : 699.95, [...] "status" : "processed", "error" : "" }, }] }, [...] "status" : "processed", "error" : ""}
  20. 20. GET / HTTP/1.1Accept: application/hal+json; profile=http://example.com/schema-v2; application/hal+json; profile=http://example.com/schema-v1; q=0.8

×