Development Lessons
description
Transcript of Development Lessons
![Page 1: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/1.jpg)
Development Lessons
of ReST APIs
Presented by Bil MowryIvy Street Technology LLC
![Page 2: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/2.jpg)
Abstract
Restful application implementation encompasses a series design, communication and testing concerns for every developer. In Development Lessons of ReST APIs, we will walk through the steps and challenges of creating a ReST API: defining, designing, documenting, and testing.
![Page 3: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/3.jpg)
Goal
The goal of this session is to share notes I have taken over several projects in thinking about, designing, implementing, testing and ReSTful services.
Focus not on implementation but rather on the output and strategies around design.
Questions! Always.
![Page 4: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/4.jpg)
Major Points
1. What is a ReST API?2. Designing3. Documenting4. Testing5. UI Considerations6. Final Thoughts
![Page 5: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/5.jpg)
1. What is a ReST API?
• Definition• What are ReST Api's good for?• Real World Examples
![Page 6: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/6.jpg)
Definition
• Representational State Transfer (REST) is an architectural style that abstracts the architectural elements within a distributed hypermedia system.[1] REST ignores the details of component implementation and protocol syntax in order to focus on the roles of components, the constraints upon their interaction with other components, and their interpretation of significant data elements.[2] REST has emerged as a predominant web API design model
• What is REST?
• REpresentational State Transfer. It describes how one system can communicate state with another. One example would be the state of a product (its name, description etc) represented as XML, JSON, or plain text. The generalised idea of state is termed a resource.
• REST is commonly associated with the web services interface since HTTP is by far the most common carrier protocol.
• REST is not HTTP. It uses HTTP because in its most general form REST exists to assist a machine in mapping the concept of a verb against an arbitrary collection of nouns. HTTP contains a useful set of generic verbs (GET, PUT, PATCH etc) that can applied to arbitrary nouns expresssed as URIs using HTTP e.g. GET http://example.org/Product(54).
• REST is not really a technology in itself, but more an architectural pattern. REST is very simple and just involves using plain XML or JSON as a communication medium, combined with URL patterns that are "representational" of the underlying system, and HTTP methods such as GET, PUT, POST and DELETE
![Page 7: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/7.jpg)
Definition
–Contracts?–CRUD?– State?– Schema/WSDL?
![Page 8: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/8.jpg)
Practically Speaking
JSON (could be XML)HTTP (Crud)Stateless (kinda)
![Page 9: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/9.jpg)
Competing Technologies?
– SOAP?– JDBC?– TCP?– WebSockets?
![Page 10: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/10.jpg)
Reasons for ReST
• Tech– Decoupling– Performance?– Portability - OS's, PLatform– Simplicity
![Page 11: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/11.jpg)
Reasons for Rest
• Business– Publically preesenting their apis's– Mashups– Monetizing
![Page 12: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/12.jpg)
Everybody's Doing ReST
• Real World Examples– Google Books:
• https://developers.google.com/books/docs/v1/using#WorkingBookshelves– Twitter
• https://dev.twitter.com/docs/api/1.1
– open BBY: • https://bbyopen.com/
• Reference - more API's– http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTcontents– http://dev.twitter.com/doc/post/statuses/destroy/:id– http://www.salesforce.com/us/developer/docs/api_rest/index.htm– http://www.flickr.com/services/api/– http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteEndpoints.html– http://www.3scale.net/– http://scottfrederick.github.io/springdoclet/ also https://github.com/kliniki-online
![Page 13: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/13.jpg)
2. Designing a ReST API
• Design your URI's• Conundrums• Payload• Frameworks• Example
![Page 14: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/14.jpg)
Design your URI's
• SEO Considerations• Verb Considerations
![Page 15: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/15.jpg)
Conundrums
• PUT vs. Post arguments, idempotency• Versioning
– SEO– Header vs URL versioning
![Page 16: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/16.jpg)
Payload
• Normalizing Your Requests/Responses– JSEND– http://labs.omniti.com/labs/jsend
• Headers & Mime Types• Error Handling
![Page 17: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/17.jpg)
Frameworks
• Restlet• NodeJS• Spring MVC• Resteasy• Jersey• Jax• Grails• Ruby Rails• PHP, Python, Perl• C#• Don't get me started on caching . . .
Use Patterns (Observer, Facade, MVC etc.)
![Page 18: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/18.jpg)
Tools
• Firebug• Rest PLugins• Fiddler• Wireshark• JSLint• curl
![Page 19: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/19.jpg)
Example
• RestNotes Grails Application
![Page 20: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/20.jpg)
3. Documenting a ReST API
• Why Document?• Tools• Examples
![Page 21: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/21.jpg)
Why Document?
• Consumers of your API• Querying the rest API
![Page 22: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/22.jpg)
Tools
• Javadocs?• Realtime Docs• Contract considerations• There are some new and totally cool tools
– 3Scale - commercial– RestletDocs– Swagger– Apiary– Mashery– Enunciate
• Some are just markup tools - @API• http://mestachs.wordpress.com/2012/08/06/rest-api-
documentation/
![Page 23: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/23.jpg)
Examples
• Apidocs for Grails• Swagger for Grails/JAX
![Page 24: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/24.jpg)
4. Testing a ReST API
• Salient Discussion Points– Unit testing– Integration Testing– Functional Testing– Acceptance Testing– BDD– TDD?– Test Server– Sharable tests -- dev, qa, consumers
![Page 25: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/25.jpg)
5. UI Considerations
• Bridge Building• Accessing ReST• Fat Clients are Dead,
Long Live Fat Clients
![Page 26: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/26.jpg)
Bridge Building
• Get that test data going• What gets computed on either side?
– A "pure" api vs catering to UI?
![Page 27: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/27.jpg)
Accessing ReST
• Each language/library can use ReST in their Repository
• HTTP libraries in Java, etc.
![Page 28: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/28.jpg)
Fat Clients are Dead, Long Live Fat Clients
• Backend ReST consumption• Fat Javascript Clients• Mobile Apps!• DualMVC idea --its a full blown
![Page 29: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/29.jpg)
6. Final Thoughts
1. What is a ReST API?2. Designing3. Documenting4. Testing5. UI Considerations6. Final Thoughts
Questions?
![Page 30: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/30.jpg)
Thank You
Kingsoft OfficeMake Presentation much more fun
Bil MowryIvy Street Technology LLC
[email protected]: 10kdev.net@bilmowry
![Page 31: Development Lessons](https://reader035.fdocuments.us/reader035/viewer/2022062305/56814ae4550346895db7f6c4/html5/thumbnails/31.jpg)
Thanks to the sponsors of this camp!