Share
Embed
Documenting RESTful APIs – Spring Exchange 2014
Slides of the talk on documenting RESTful APIs that I gave at Spring Exchange 2014
Andy Wilkinson
November 07, 2014
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.
Transcript
38 slides
-
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Documenting RESTful APIs Andy Wilkinson, Pivotal @ankinson -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How RESTful is your API? 2 -
Hyper media HTTP verbs Separate Resources Unless otherwise indicated, these
slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 3 XML-RPC SOAP RPC REST maturity model http://www.crummy.com/writing/speaking/2008-QCon/act3.html http://martinfowler.com/articles/richardsonMaturityModel.html Level 0 Level 1 Level 2 Level 3 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How RESTful do you want it to be? 4 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Making your API easy to document 5 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Consistency HTTP status codes HTTP verbs 6 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Uniqueness Use distinct relations on your links 7 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ { "_links" : { "notes" : { "href" : "http://localhost:8080/notes" }, "tags" : { "href" : "http://localhost:8080/tags" } } } 8 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What should you document? 9 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Resources What do they represent? What input do they accept? What output do they produce? 10 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Links Where can you go? What will you find when you get there? 11 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Cross-cutting concerns HTTP status codes HTTP verbs (PUT vs PATCH) Authentication and authorisation Rate limiting … 12 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What shouldn’t you document? 13 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ URIs 14 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What does it look when you get it wrong? ! Learning from my mistakes 15 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 16 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ And when you get it right? 17 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 18 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ RESTful API documentation tools 19 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Swagger http://swagger.io 20 martypitt/swagger-springmvc -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ It doesn’t support hypermedia 21 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ It’s URI centric 22 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ It’s leaky 23 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ It’s huge 24 Spring Boot Tomcat Hibernate 25MB ! Swagger ! 31MB -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ HAL and HAL Browser http://stateless.co/hal_specification.html ! 25 mikekelly/hal-browser -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ A new alternative 26 wilkinsona/spring-restdocs -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Write as much as possible in a format that’s designed for writing 27 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Don’t use the implementation to provide the documentation 28 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Provide some guarantees that the documentation is accurate 29 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Asciidoctor Spring MVC Test Gradle plugin 30 wilkinsona/spring-restdocs -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 31 @Test public void indexExample() throws Exception { document("index-example", this.mockMvc.perform(get("/")) .andExpect(status().isOk())) .andExpect(jsonPath("_links.notes", is(notNullValue()))) .andExpect(jsonPath("_links.tags", is(notNullValue()))); } 1 2 3 4 5 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 32 [source,http] ---- HTTP/1.1 200 OK Content-Type: application/hal+json ! { "_links" : { "tags" : { "href" : "http://localhost:8080/tags" }, "notes" : { "href" : "http://localhost:8080/notes" } } -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 33 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 34 @Test public void indexExample() throws Exception { document("index-example", this.mockMvc.perform(get("/")) .andExpect(status().isOk())) .andDocumentLinks(halLinks(), linkWithRel("notes").description( "The <<resources-notes,Notes resource>>"), linkWithRel("tags").description( "The <<resources-tags,Tags resource>>")); } 1 2 3 4 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 35 |=== | Relation | Description ! | notes | The <<resources-notes,Notes resource>> ! | tags | The <<resources-tags,Tags resource>> |=== -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 36 -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Please try it out I’d love your feedback 37 wilkinsona/spring-restdocs -
Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,
Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Thank you 38 @ankinson wilkinsona [email protected]