Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Api chaining(tm)

Talk from RestFest on how API Chaining(tm) works in chaining multiple api calls with one request and response without redirects.

  • Login to see the comments

Api chaining(tm)

  1. 1. RestFest 2017 orubel@gmail.comOwen Rubel API Chaining™ & API Abstraction
  2. 2. Title Text RestFest 2017 orubel@gmail.comOwen Rubel What is API Chaining™? “ API Chaining is a monad allowing a series of api calls to be passed and processed using one REQUEST/RESPONSE.”
  3. 3. Title Text RestFest 2017 orubel@gmail.comOwen Rubel • Abstraction of Communication Logic/Data from Biz Logic • Internal Redirect Handling in API Service • Separated Communication Data from Communication Logic Requirements for API Chaining™
  4. 4. Title Text RestFest 2017 orubel@gmail.comOwen Rubel Understanding API Abstraction
  5. 5. Title Text RestFest 2017 orubel@gmail.comOwen Rubel “ An API is Standardized Input/Output (I/O) to/from a Separation of Concern (usually being Business Logic).” In Short : What Is An API? (1 OF 2)
  6. 6. Title Text RestFest 2017 orubel@gmail.comOwen Rubel What Is An API? (2 OF 2) owenr@uw.edu
  7. 7. Title Text RestFest 2017 orubel@gmail.comOwen Rubel What Is Separation of Concern? (2 of 2) Bound Secondary Concern (Communication Logic) Primary Concern (Business Logic)
  8. 8. Title Text RestFest 2017 orubel@gmail.comOwen Rubel “ In computer science, separation of concerns (SoC) is a design principle for separating a computer program into distinct sections, such that each section addresses a separate concern. A concern is a set of information that affects the code of a computer program” (ex HTML, CSS, JS) - Source : Separation Of Concern, Wikipedia What Is Separation of Concern?
  9. 9. Title Text RestFest 2017 orubel@gmail.comOwen Rubel API Pattern in Distributed Architecture
  10. 10. Title Text RestFest 2017 orubel@gmail.comOwen Rubel API Pattern in Distributed Architecture
  11. 11. Title Text RestFest 2017 orubel@gmail.comOwen Rubel API Pattern in Distributed Architecture
  12. 12. Title Text RestFest 2017 orubel@gmail.comOwen Rubel “Cross-cutting concerns can be directly responsible for tangling, or system inter-dependencies, within a program. Because procedural and functional language constructs consist entirely of procedure calling, there is no semantic through where two goals (the capability to be implemented and the related cross- cutting concern) can be addressed simultaneously.[3] As a result, the code addressing the cross-cutting concern must be scattered, or duplicated, across the various related locations, resulting in a loss of modularity.[2]” - Source : Cross Cutting Concern, Wikipedia What is a Cross Cutting Concern?
  13. 13. Title Text RestFest 2017 orubel@gmail.comOwen Rubel • Synchronization • Real-time constraints • Error detection and correction • Product features • Memory management • Data validation • Persistence • Transaction processing • Internationalization and localization which includes Language localisation • Information security • Caching • Logging • Monitoring • Business rules • Code mobility • Domain-specific optimizations Issues of a Cross Cutting Concern
  14. 14. Title Text RestFest 2017 orubel@gmail.comOwen Rubel This is The API Patterns Brick Wall Brick Wall
  15. 15. Title Text RestFest 2017 orubel@gmail.comOwen Rubel So How Do We Fix?
  16. 16. Title Text RestFest 2017 orubel@gmail.comOwen Rubel Old API Pattern in MVC redirect/response
  17. 17. Title Text RestFest 2017 orubel@gmail.comOwen Rubel New API Pattern in MVC
  18. 18. Title Text RestFest 2017 orubel@gmail.comOwen Rubel Shared I/O State In Distributed Architecture
  19. 19. Title Text RestFest 2017 orubel@gmail.comOwen Rubel This handles the Redirect and allows communication to take place internally when needed…
  20. 20. Title Text RestFest 2017 orubel@gmail.comOwen Rubel This allows: • Central Piece of architecture (where REQUEST AND RESPONSE are handled) to be ‘Single Version of Truth’ (SOV) called ‘IO State’ • All services can sync data from SOV • Failure of SOV DOES NOT affect synchronization of data • Reload state on the fly at SOV and update ALL subscribed services Shared IO State
  21. 21. Title Text RestFest 2017 orubel@gmail.comOwen Rubel So What Is IO State?
  22. 22. Title Text RestFest 2017 orubel@gmail.comOwen Rubel What is IO State? • Caches Communications Data • Synchronizes Architectural Props (distribute rules of communication) • Handles API Authorizations (access for communication) • Api Docs Definitions (how to communicate) I/O State is data directly related to a request/response, normally separated from functionality. Handles all data associated with communication and communication access
  23. 23. Title Text RestFest 2017 orubel@gmail.comOwen Rubel What Does IO State Contain •Data specifically related to I/O (request/response); not data related to function (ie, errors, how to process, etc).all the data contained in annotations act as rules associated with the URI endpoint (not URL or the FQDN) •by containing all those rules in one file and caching that data, we can share it with the other architectural components (and abstract data from functionality) •this enables us to change it on the fly and reload without having to restart any services allowing subscribed services to get changes pushed to them through web hooks
  24. 24. Title Text RestFest 2017 orubel@gmail.comOwen Rubel I/O State : Communications Properties Shared I/O State is ‘IO State’ data unbound from functionality so that it can be shared across architectural components. This is the approach used by distributed architectures. Bound I/O State is ‘I/O State’ data bound to functionality which cannot be shared or synchronized with additional architectural components creating an ‘architectural cross cutting concern’. This is commonly found in centralized architectures.
  25. 25. Title Text RestFest 2017 orubel@gmail.comOwen Rubel So How Do We Fix?
  26. 26. Title Text RestFest 2017 orubel@gmail.comOwen Rubel Shared I/O State • DOESN’T bind to the application • DOESN’T bind to functionality • DOESN’T bind to a resource
  27. 27. Title Text RestFest 2017 orubel@gmail.comOwen Rubel What Does It Look Like? Title Text https://gist.github.com/orubel/7c4d0290c7b8896667a3
  28. 28. Title Text RestFest 2017 orubel@gmail.comOwen Rubel • RAML, OpenAPI, Swagger, API BluePrint • not role based; endpoints need to be checked via token roles • limited to CRUD-based REST of 4 calls per class • duplicitous; lack of separation • Confuses API data with functionality
  29. 29. Title Text RestFest 2017 orubel@gmail.comOwen Rubel • Dramatic Code reduction By Reducing Duplication • Automation of nearly all aspects of API • 0% downtime for changes to endpoint data and rules • New API Patterns (ie API Chaining (tm) ) What Does It Improve?
  30. 30. Title Text RestFest 2017 orubel@gmail.comOwen Rubel Code Reduction (1 of 2) Controller : Mixed Concerns (Duplication) @Secured(['ROLE_ADMIN', ‘ROLE_USER']) @RequestMapping(value="/create", method=RequestMethod.POST) @ResponseBody public ModelAndView createAddress(){ List authorities = springSecurityService.getPrincipal().getAuthorities() User user if(authorities.contains(‘ROLE_ADMIN’)){ if(params.id){ user = User.get(params.id.toLong()) }else{ render(status:HttpServletResponse.SC_BAD_REQUEST) } }else if(authorities.contains(‘ROLE_USER’)){ user = User.get(principal.id) } Address address = new Address(params) … address.user = user …
  31. 31. Title Text RestFest 2017 orubel@gmail.comOwen Rubel Code Reduction (2 of 2) Controller : Single Concern public ModelAndView createAddress(){ User user= (params.id)?User.get(params.id.toLong()): User.get(principal.id) Address address = new Address(params) address.user = user … }
  32. 32. Title Text RestFest 2017 orubel@gmail.comOwen Rubel This allows for new Patterns like API Chaining™…
  33. 33. Title Text RestFest 2017 orubel@gmail.comOwen Rubel • Post Chain • GET > GET > (PUT/POST/DELETE) • Pre Chain • (PUT/POST/DELETE) > GET > GET • Blank Chain • GET > GET > GET Three types of Chains
  34. 34. Title Text RestFest 2017 orubel@gmail.comOwen Rubel What data is sent for a chain API Chain Data { <put/post data (if applicable)>, chain:{ key:dept_id, combine:'false', type:'postchain', order:{dept/show:company_id,company/update:return} } }
  35. 35. Title Text RestFest 2017 orubel@gmail.comOwen Rubel Chain Examples GET Chain Example PUT Chain Example curl -v -i -H "Content-Type: application/json" -H "Authorization: Bearer <token>" --request PUT -d " {'testdata':'testamundo','chain':{'key':'sectionId','combine':'false','type':'postchain','order': {'section/get':'id','section/update':'return'}}}" "http://localhost:8080/c0.1/post/show/1" curl -v -i -H "Content-Type: application/json" -H "Authorization: Bearer <token>" --request GET -d " {'chain':{'key':'Id','combine':'false','type':'blankchain','order':{'postTopic/ showByTopic':'postId','post/show':'return'}}}" "http://localhost:8080/c0.1/topic/show/1"
  36. 36. Title Text RestFest 2017 orubel@gmail.comOwen Rubel More documentation on API Chaining API Chaining™ Documentation http://orubel.github.io/Beapi-API-Framework/chain.html
  37. 37. Title Text RestFest 2017 orubel@gmail.comOwen Rubel DEMO
  38. 38. RestFest 2017 orubel@gmail.comOwen Rubel Questions? (please contact for business opportunities or hiring)

×