SlideShare a Scribd company logo
2015Vladimir Tsukur
Building
AWESOME API
with
REST
2
Vladimir Tsukur
partner @
engineer @
engineer /
architect @
flushdia vtsukur
3
Web API? Why Should I Care?
Idea! Currency
Black Market!
5
finance.i.ua - Listing
6
finance.i.ua - Ad Creation
7
8
Spring Boot
Tools
Spring Data
Spring Data REST
CODING TIME !
10
CRUD Style API
Method URL Task
POST /ads Create ad
GET /ads View ads
GET /ads/{id} Get ad
PATCH /ads/{id} Update ad
DELETE /ads/{id} Delete ad
11
I am
sorry, but we have
business process
12
if (status == Status.NEW) {
publishedAt = LocalDateTime.now();
status = Status.PUBLISHED;
} …
CRUD is NOT enough
if (status == Status.NEW) {
publishedAt = LocalDateTime.now();
status = Status.PUBLISHED;
} …
13
API Changes
Method URL Task
POST /ads/{id}/publishing Publish ad
POST /ads/{id}/expiration Expire ad
GET /ads/search/published
Get published
ads
CODING TIME !
/uri Style Adoption?
43%
16
17
URI Binding & Construction
Task Method URL
Update ad PATCH /ads/{id}
Delete ad DELETE /ads/{id}
Publish ad POST
/ads/{id}/
publishing
Expire ad POST
/ads/{id}/
expiration
18
"Figuring" Out the Flow
Task Method URL
Update ad
(only if NEW) PATCH /ads/{id}
Delete ad
(only if NEW) DELETE /ads/{id}
Publish ad
(only if NEW) POST
/ads/{id}/
publishing
Expire ad
(only if
PUBLISHED)
POST
/ads/{id}/
expiration
Should work on my
iPhone 6s!
20
21
Hypermedia =
{
"amount": 3000,
"currency": "USD",
…
}
data
{
…
"_links": {
"publishing": {
"href": "/ads/1/publishing"
},
"update": {
"href": "/ads/1"
},
"deletion": {
"href": "/ads/1"
},
…
}
}
links
+
22
Hypermedia API
Link
Relation
Task Method
update Update ad PATCH
deletion Delete ad DELETE
publishing Publish ad POST
expiration Expire ad POST
23
Tools
Spring HATEOAS
CODING TIME !
25
HAL = Hypertext Application
Language
"I want hypermedia!"
40%
27
28
Siren Actions
"actions": [
{
"name": "create-ad",
"method": "POST",
"href": "/ads",
"type": "application/json",
"fields": [
{ "name": "type", "type": "radio" },
{ "name": "quantity", "type": "number" },
{ "name": "currency", "type": "radio" },
…
]
}
]
I want a
convenient
browser for
HAL …
ASAP!
SHOW TIME !
We are ready
to go to prod,
right ;)?
32
No, we are not!
1. Data View Customization
2. Validation
3. Application Events
4. Caching / Version Control
5. Security
6. Export Control
7. …
33
Getting awesome!
1. Data View Customization
2. Validation
3. Application Events
4. Caching / Version Control
5. Security
6. Export Control
7. …
34
Integration Domain Model
{
"id": 345,
"type": "SELL",
"amount": 3000,
"currency": "USD",
"rate": 25.25,
"location": {
"city": "Одесса",
"area": "Приморский"
},
"comment": "быстрее детка!",
"publishedAt": "…07:52:22…",
"status": "PUBLISHED",
…
}
{
"type": "SELL",
"amount": 3000,
"currency": "USD",
"rate": 25.25,
"phoneNumber": "+380…"
…
}
CODING TIME !
36
Getting awesome!
1. Data View Customization
2. Validation
3. Application Events
4. Caching / Version Control
5. Security
6. Export Control
7. …
CODING TIME !
SECURITY
CODING TIME !
Testing?
Documentation?
41
SHOW TIME !
Building Awesome API with Spring
44
Outcomes - API
1. Use links for state transitions
2. Separate integration domain
from the core domain
3. Expose only the necessary parts
4. Leverage caching
5. Combine testing with
documentation
6. Do NOT document URLs!
45
Outcomes -
1. Spring Data REST - simple, CRUD-
y and HATEOAS-y; extensible
PRO TIP: won't solve everything
2. Spring MVC - always there to help
3. Link stuff with Spring HATEOAS
4. Spring Security to the rescue
when you need to protect API
5. Document with Spring REST Docs
46
Thanks!
Questions?
https://github.com/vtsukur/spring-rest-black-market
47
Thanks!
Questions?
48
References
1. http://www.google.com.ua/trends/explore#q=web%20api%2C%20rest%20api&cmpt=q&tz=
2. http://finance.i.ua/market/
3. http://projects.spring.io/spring-boot/
4. http://projects.spring.io/spring-data/
5. http://docs.spring.io/spring-data/jpa/docs/1.7.2.RELEASE/reference/html/
6. http://projects.spring.io/spring-data-rest/
7. http://docs.spring.io/spring-data/rest/docs/2.3.0.RELEASE/reference/html/
8. https://spring.io/blog/2014/07/14/spring-data-rest-now-comes-with-alps-metadata
9. http://projects.spring.io/spring-hateoas/
10. http://docs.spring.io/spring-hateoas/docs/0.17.0.RELEASE/reference/html/
11. https://github.com/spring-projects/spring-restdocs
12. https://blog.akana.com/hypermedia-apis
13. http://www.apiacademy.co/lessons/api-design/web-api-architectural-styles
14. http://www.programmableweb.com/news/modern-api-architectural-styles-offer-developers-choices/2014/06/13
15. https://en.wikipedia.org/wiki/Hypermedia
16. http://stateless.co/hal_specification.html
17. https://github.com/kevinswiber/siren
18. https://www.mnot.net/blog/2013/06/23/linking_apis
19. http://oredev.org/2010/sessions/hypermedia-apis
20. http://vimeo.com/75106815
21. https://www.innoq.com/blog/st/2012/06/hypermedia-benefits-for-m2m-communication/
22. http://ws-rest.org/2014/sites/default/files/wsrest2014_submission_12.pdf
23. http://www.infoq.com/news/2014/03/ca-api-survey
24. https://twitter.com/hypermediaapis
25. https://www.youtube.com/watch?v=hdSrT4yjS1g
26. https://www.youtube.com/watch?v=mZ8_QgJ5mbs
27. http://nordsc.com/ext/classification_of_http_based_apis.html
28. http://soabits.blogspot.no/2013/12/selling-benefits-of-hypermedia.html
29. https://github.com/mamund/Building-Hypermedia-APIs
30. http://tech.blog.box.com/2013/04/get-developer-hugs-with-rich-error-handling-in-your-api/
49
Images
1. http://www.google.com.ua/trends/explore#q=web%20api%2C%20rest%20api&cmpt=q&tz=
2. http://finance.i.ua/market/
3. http://projects.spring.io/spring-boot/
4. http://projects.spring.io/spring-data/
5. http://docs.spring.io/spring-data/jpa/docs/1.7.2.RELEASE/reference/html/
6. http://projects.spring.io/spring-data-rest/
7. http://docs.spring.io/spring-data/rest/docs/2.3.0.RELEASE/reference/html/
8. https://spring.io/blog/2014/07/14/spring-data-rest-now-comes-with-alps-metadata
9. http://projects.spring.io/spring-hateoas/
10. http://docs.spring.io/spring-hateoas/docs/0.17.0.RELEASE/reference/html/
11. https://github.com/spring-projects/spring-restdocs
12. https://blog.akana.com/hypermedia-apis
13. http://www.apiacademy.co/lessons/api-design/web-api-architectural-styles
14. http://www.programmableweb.com/news/modern-api-architectural-styles-offer-developers-choices/2014/06/13
15. https://en.wikipedia.org/wiki/Hypermedia
16. http://stateless.co/hal_specification.html
17. https://github.com/kevinswiber/siren
18. https://www.mnot.net/blog/2013/06/23/linking_apis
19. http://oredev.org/2010/sessions/hypermedia-apis
20. http://vimeo.com/75106815
21. https://www.innoq.com/blog/st/2012/06/hypermedia-benefits-for-m2m-communication/
22. http://ws-rest.org/2014/sites/default/files/wsrest2014_submission_12.pdf
23. http://www.infoq.com/news/2014/03/ca-api-survey
24. https://twitter.com/hypermediaapis
25. https://www.youtube.com/watch?v=hdSrT4yjS1g
26. https://www.youtube.com/watch?v=mZ8_QgJ5mbs
27. http://nordsc.com/ext/classification_of_http_based_apis.html
28. http://soabits.blogspot.no/2013/12/selling-benefits-of-hypermedia.html
29. https://github.com/mamund/Building-Hypermedia-APIs
30. http://tech.blog.box.com/2013/04/get-developer-hugs-with-rich-error-handling-in-your-api/
31. http://img.112.ua/original/2015/01/16/114777.jpg
32. http://eimg.pravda.com/images/doc/6/7/6700cff-hontareva.jpg
33. http://imgcdn1.luxnet.ua/tv24/resources/newsfiles/201502/121.jpg
34. http://beta2.odessa-daily.com.ua/uploads/imgsc/
84d27d3a6af024c32b16c54216e01777d50c625d_b_fa55cd70c403167a5277a6db96eb8c7c2b6139d4.jpg

More Related Content

What's hot (19)

PDF
Building Beautiful REST APIs in ASP.NET Core
Stormpath
 
PDF
The never-ending REST API design debate -- Devoxx France 2016
Restlet
 
ODP
Attacking REST API
Siddharth Bezalwar
 
PDF
GraphQL - gdy API RESTowe to za mało
MarcinStachniuk
 
PDF
[DevCrowd] GraphQL - gdy API RESTowe to za mało
MarcinStachniuk
 
PDF
GraphQL - when REST API is to less - lessons learned
MarcinStachniuk
 
PPTX
Best practices for RESTful web service design
Ramin Orujov
 
PDF
HATEOAS: The Confusing Bit from REST
elliando dias
 
PDF
Take a REST!
Vladimir Tsukur
 
PDF
Rest - Representational State Transfer (EMC BRDC Internal Tech talk)
Rodrigo Senra
 
PDF
RESTful Web Services
Christopher Bartling
 
PDF
BruJUG Brussels GraphQL when RESR API is to less - lessons learned
MarcinStachniuk
 
PPTX
How to implement email functionalities with Mailjet api
E Boisgontier
 
PDF
Representational State Transfer (REST)
David Krmpotic
 
PPTX
The REST And Then Some
Nordic APIs
 
PPT
Understanding REST
Nitin Pande
 
PPTX
Introduction to Hydra
Alejandro Inestal
 
PPTX
Restful webservices
Luqman Shareef
 
PDF
What is REST API? REST API Concepts and Examples | Edureka
Edureka!
 
Building Beautiful REST APIs in ASP.NET Core
Stormpath
 
The never-ending REST API design debate -- Devoxx France 2016
Restlet
 
Attacking REST API
Siddharth Bezalwar
 
GraphQL - gdy API RESTowe to za mało
MarcinStachniuk
 
[DevCrowd] GraphQL - gdy API RESTowe to za mało
MarcinStachniuk
 
GraphQL - when REST API is to less - lessons learned
MarcinStachniuk
 
Best practices for RESTful web service design
Ramin Orujov
 
HATEOAS: The Confusing Bit from REST
elliando dias
 
Take a REST!
Vladimir Tsukur
 
Rest - Representational State Transfer (EMC BRDC Internal Tech talk)
Rodrigo Senra
 
RESTful Web Services
Christopher Bartling
 
BruJUG Brussels GraphQL when RESR API is to less - lessons learned
MarcinStachniuk
 
How to implement email functionalities with Mailjet api
E Boisgontier
 
Representational State Transfer (REST)
David Krmpotic
 
The REST And Then Some
Nordic APIs
 
Understanding REST
Nitin Pande
 
Introduction to Hydra
Alejandro Inestal
 
Restful webservices
Luqman Shareef
 
What is REST API? REST API Concepts and Examples | Edureka
Edureka!
 

Similar to Building Awesome API with Spring (20)

PDF
From REST to Hypermedia APIs with Spring by Vladimir Tsukur
JavaDayUA
 
PDF
From CRUD to Hypermedia APIs with Spring
GlobalLogic Ukraine
 
PPTX
Startup Safary | Fight against robots with enbrite.ly data platform
Mészáros József
 
PDF
Scaling business app development with Play and Scala
Peter Hilton
 
PDF
Do more with less code in a serverless world
jeromevdl
 
PPTX
How to Leverage APIs for SEO #TTTLive2019
Paul Shapiro
 
PPTX
How to leverage APIs & Scrapers in App Store Optimization
Romain Golfier
 
PDF
Creditas Digital Platform: How we enabled business users to create new digita...
Software Guru
 
PDF
Leveraging exponential creation of Digital Products through a Digital Platform
Evandro Silvestre
 
PDF
PHPUnit Episode iv.iii: Return of the tests
Michelangelo van Dam
 
PPTX
Microsoft Graph: Connect to essential data every app needs
Microsoft Tech Community
 
PPTX
Microsoft Graph: Connect to essential data every app needs
Microsoft Tech Community
 
PPTX
Budapest Spark Meetup - Apache Spark @enbrite.ly
Mészáros József
 
PDF
The Future of Progressive Web Apps - View Source conference, Berlin 2016
Robert Nyman
 
PPTX
Enabling Machine Learning with Apache Flink - Sherin Thomas, Lyft
Flink Forward
 
PDF
Real-time search in Drupal with Elasticsearch @Moldcamp
Alexei Gorobets
 
PDF
[@IndeedEng] Logrepo: Enabling Data-Driven Decisions
indeedeng
 
KEY
Creating Professional Applications with the LinkedIn API
Kirsten Hunter
 
PDF
Prisma the ORM that node was waiting for
Commit University
 
PPTX
Expanding APIs beyond the Web
Tim Messerschmidt
 
From REST to Hypermedia APIs with Spring by Vladimir Tsukur
JavaDayUA
 
From CRUD to Hypermedia APIs with Spring
GlobalLogic Ukraine
 
Startup Safary | Fight against robots with enbrite.ly data platform
Mészáros József
 
Scaling business app development with Play and Scala
Peter Hilton
 
Do more with less code in a serverless world
jeromevdl
 
How to Leverage APIs for SEO #TTTLive2019
Paul Shapiro
 
How to leverage APIs & Scrapers in App Store Optimization
Romain Golfier
 
Creditas Digital Platform: How we enabled business users to create new digita...
Software Guru
 
Leveraging exponential creation of Digital Products through a Digital Platform
Evandro Silvestre
 
PHPUnit Episode iv.iii: Return of the tests
Michelangelo van Dam
 
Microsoft Graph: Connect to essential data every app needs
Microsoft Tech Community
 
Microsoft Graph: Connect to essential data every app needs
Microsoft Tech Community
 
Budapest Spark Meetup - Apache Spark @enbrite.ly
Mészáros József
 
The Future of Progressive Web Apps - View Source conference, Berlin 2016
Robert Nyman
 
Enabling Machine Learning with Apache Flink - Sherin Thomas, Lyft
Flink Forward
 
Real-time search in Drupal with Elasticsearch @Moldcamp
Alexei Gorobets
 
[@IndeedEng] Logrepo: Enabling Data-Driven Decisions
indeedeng
 
Creating Professional Applications with the LinkedIn API
Kirsten Hunter
 
Prisma the ORM that node was waiting for
Commit University
 
Expanding APIs beyond the Web
Tim Messerschmidt
 
Ad

More from Vladimir Tsukur (7)

PDF
GraphQL APIs in Scala with Sangria
Vladimir Tsukur
 
PDF
GraphQL - APIs The New Way
Vladimir Tsukur
 
PDF
Hot and spicy Java with Lombok. Live!
Vladimir Tsukur
 
PDF
Law of Demeter & Objective Sense of Style
Vladimir Tsukur
 
PDF
Abstraction Classes in Software Design
Vladimir Tsukur
 
PDF
Acceptance Testing of Web UI
Vladimir Tsukur
 
KEY
REpresentational State Transfer
Vladimir Tsukur
 
GraphQL APIs in Scala with Sangria
Vladimir Tsukur
 
GraphQL - APIs The New Way
Vladimir Tsukur
 
Hot and spicy Java with Lombok. Live!
Vladimir Tsukur
 
Law of Demeter & Objective Sense of Style
Vladimir Tsukur
 
Abstraction Classes in Software Design
Vladimir Tsukur
 
Acceptance Testing of Web UI
Vladimir Tsukur
 
REpresentational State Transfer
Vladimir Tsukur
 
Ad

Recently uploaded (20)

PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Advancing WebDriver BiDi support in WebKit
Igalia
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
July Patch Tuesday
Ivanti
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Advancing WebDriver BiDi support in WebKit
Igalia
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 

Building Awesome API with Spring

  • 2. REST 2 Vladimir Tsukur partner @ engineer @ engineer / architect @ flushdia vtsukur
  • 3. 3 Web API? Why Should I Care?
  • 7. 7
  • 10. 10 CRUD Style API Method URL Task POST /ads Create ad GET /ads View ads GET /ads/{id} Get ad PATCH /ads/{id} Update ad DELETE /ads/{id} Delete ad
  • 11. 11 I am sorry, but we have business process
  • 12. 12 if (status == Status.NEW) { publishedAt = LocalDateTime.now(); status = Status.PUBLISHED; } … CRUD is NOT enough if (status == Status.NEW) { publishedAt = LocalDateTime.now(); status = Status.PUBLISHED; } …
  • 13. 13 API Changes Method URL Task POST /ads/{id}/publishing Publish ad POST /ads/{id}/expiration Expire ad GET /ads/search/published Get published ads
  • 16. 16
  • 17. 17 URI Binding & Construction Task Method URL Update ad PATCH /ads/{id} Delete ad DELETE /ads/{id} Publish ad POST /ads/{id}/ publishing Expire ad POST /ads/{id}/ expiration
  • 18. 18 "Figuring" Out the Flow Task Method URL Update ad (only if NEW) PATCH /ads/{id} Delete ad (only if NEW) DELETE /ads/{id} Publish ad (only if NEW) POST /ads/{id}/ publishing Expire ad (only if PUBLISHED) POST /ads/{id}/ expiration
  • 19. Should work on my iPhone 6s!
  • 20. 20
  • 21. 21 Hypermedia = { "amount": 3000, "currency": "USD", … } data { … "_links": { "publishing": { "href": "/ads/1/publishing" }, "update": { "href": "/ads/1" }, "deletion": { "href": "/ads/1" }, … } } links +
  • 22. 22 Hypermedia API Link Relation Task Method update Update ad PATCH deletion Delete ad DELETE publishing Publish ad POST expiration Expire ad POST
  • 25. 25 HAL = Hypertext Application Language
  • 27. 27
  • 28. 28 Siren Actions "actions": [ { "name": "create-ad", "method": "POST", "href": "/ads", "type": "application/json", "fields": [ { "name": "type", "type": "radio" }, { "name": "quantity", "type": "number" }, { "name": "currency", "type": "radio" }, … ] } ]
  • 29. I want a convenient browser for HAL … ASAP!
  • 31. We are ready to go to prod, right ;)?
  • 32. 32 No, we are not! 1. Data View Customization 2. Validation 3. Application Events 4. Caching / Version Control 5. Security 6. Export Control 7. …
  • 33. 33 Getting awesome! 1. Data View Customization 2. Validation 3. Application Events 4. Caching / Version Control 5. Security 6. Export Control 7. …
  • 34. 34 Integration Domain Model { "id": 345, "type": "SELL", "amount": 3000, "currency": "USD", "rate": 25.25, "location": { "city": "Одесса", "area": "Приморский" }, "comment": "быстрее детка!", "publishedAt": "…07:52:22…", "status": "PUBLISHED", … } { "type": "SELL", "amount": 3000, "currency": "USD", "rate": 25.25, "phoneNumber": "+380…" … }
  • 36. 36 Getting awesome! 1. Data View Customization 2. Validation 3. Application Events 4. Caching / Version Control 5. Security 6. Export Control 7. …
  • 41. 41
  • 44. 44 Outcomes - API 1. Use links for state transitions 2. Separate integration domain from the core domain 3. Expose only the necessary parts 4. Leverage caching 5. Combine testing with documentation 6. Do NOT document URLs!
  • 45. 45 Outcomes - 1. Spring Data REST - simple, CRUD- y and HATEOAS-y; extensible PRO TIP: won't solve everything 2. Spring MVC - always there to help 3. Link stuff with Spring HATEOAS 4. Spring Security to the rescue when you need to protect API 5. Document with Spring REST Docs
  • 48. 48 References 1. http://www.google.com.ua/trends/explore#q=web%20api%2C%20rest%20api&cmpt=q&tz= 2. http://finance.i.ua/market/ 3. http://projects.spring.io/spring-boot/ 4. http://projects.spring.io/spring-data/ 5. http://docs.spring.io/spring-data/jpa/docs/1.7.2.RELEASE/reference/html/ 6. http://projects.spring.io/spring-data-rest/ 7. http://docs.spring.io/spring-data/rest/docs/2.3.0.RELEASE/reference/html/ 8. https://spring.io/blog/2014/07/14/spring-data-rest-now-comes-with-alps-metadata 9. http://projects.spring.io/spring-hateoas/ 10. http://docs.spring.io/spring-hateoas/docs/0.17.0.RELEASE/reference/html/ 11. https://github.com/spring-projects/spring-restdocs 12. https://blog.akana.com/hypermedia-apis 13. http://www.apiacademy.co/lessons/api-design/web-api-architectural-styles 14. http://www.programmableweb.com/news/modern-api-architectural-styles-offer-developers-choices/2014/06/13 15. https://en.wikipedia.org/wiki/Hypermedia 16. http://stateless.co/hal_specification.html 17. https://github.com/kevinswiber/siren 18. https://www.mnot.net/blog/2013/06/23/linking_apis 19. http://oredev.org/2010/sessions/hypermedia-apis 20. http://vimeo.com/75106815 21. https://www.innoq.com/blog/st/2012/06/hypermedia-benefits-for-m2m-communication/ 22. http://ws-rest.org/2014/sites/default/files/wsrest2014_submission_12.pdf 23. http://www.infoq.com/news/2014/03/ca-api-survey 24. https://twitter.com/hypermediaapis 25. https://www.youtube.com/watch?v=hdSrT4yjS1g 26. https://www.youtube.com/watch?v=mZ8_QgJ5mbs 27. http://nordsc.com/ext/classification_of_http_based_apis.html 28. http://soabits.blogspot.no/2013/12/selling-benefits-of-hypermedia.html 29. https://github.com/mamund/Building-Hypermedia-APIs 30. http://tech.blog.box.com/2013/04/get-developer-hugs-with-rich-error-handling-in-your-api/
  • 49. 49 Images 1. http://www.google.com.ua/trends/explore#q=web%20api%2C%20rest%20api&cmpt=q&tz= 2. http://finance.i.ua/market/ 3. http://projects.spring.io/spring-boot/ 4. http://projects.spring.io/spring-data/ 5. http://docs.spring.io/spring-data/jpa/docs/1.7.2.RELEASE/reference/html/ 6. http://projects.spring.io/spring-data-rest/ 7. http://docs.spring.io/spring-data/rest/docs/2.3.0.RELEASE/reference/html/ 8. https://spring.io/blog/2014/07/14/spring-data-rest-now-comes-with-alps-metadata 9. http://projects.spring.io/spring-hateoas/ 10. http://docs.spring.io/spring-hateoas/docs/0.17.0.RELEASE/reference/html/ 11. https://github.com/spring-projects/spring-restdocs 12. https://blog.akana.com/hypermedia-apis 13. http://www.apiacademy.co/lessons/api-design/web-api-architectural-styles 14. http://www.programmableweb.com/news/modern-api-architectural-styles-offer-developers-choices/2014/06/13 15. https://en.wikipedia.org/wiki/Hypermedia 16. http://stateless.co/hal_specification.html 17. https://github.com/kevinswiber/siren 18. https://www.mnot.net/blog/2013/06/23/linking_apis 19. http://oredev.org/2010/sessions/hypermedia-apis 20. http://vimeo.com/75106815 21. https://www.innoq.com/blog/st/2012/06/hypermedia-benefits-for-m2m-communication/ 22. http://ws-rest.org/2014/sites/default/files/wsrest2014_submission_12.pdf 23. http://www.infoq.com/news/2014/03/ca-api-survey 24. https://twitter.com/hypermediaapis 25. https://www.youtube.com/watch?v=hdSrT4yjS1g 26. https://www.youtube.com/watch?v=mZ8_QgJ5mbs 27. http://nordsc.com/ext/classification_of_http_based_apis.html 28. http://soabits.blogspot.no/2013/12/selling-benefits-of-hypermedia.html 29. https://github.com/mamund/Building-Hypermedia-APIs 30. http://tech.blog.box.com/2013/04/get-developer-hugs-with-rich-error-handling-in-your-api/ 31. http://img.112.ua/original/2015/01/16/114777.jpg 32. http://eimg.pravda.com/images/doc/6/7/6700cff-hontareva.jpg 33. http://imgcdn1.luxnet.ua/tv24/resources/newsfiles/201502/121.jpg 34. http://beta2.odessa-daily.com.ua/uploads/imgsc/ 84d27d3a6af024c32b16c54216e01777d50c625d_b_fa55cd70c403167a5277a6db96eb8c7c2b6139d4.jpg