The Power of a Great API Damian Brady Microsoft Ignite 2015 2/19/2019 8:28 AM The Power of a Great API The case for writing API-first applications Damian Brady ARC341B © 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Why is an API a good thing? Implementation Demo Microsoft Ignite 2015 2/19/2019 8:28 AM Why is an API a good thing? Implementation Demo © 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
I need one button to disable all the machines in an environment ❄️
Solution One “Sorry, you’re going to have to do it 200 times” Microsoft Ignite 2015 2/19/2019 8:28 AM Solution One “Sorry, you’re going to have to do it 200 times” © 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Solution Two “Sure! We’ll add that!” Microsoft Ignite 2015 2/19/2019 8:28 AM Solution Two “Sure! We’ll add that!” © 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Solution Three “Here’s a script”
API Microsoft Ignite 2015 2/19/2019 8:28 AM © 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
UNTAPPD
API != Public API
Implementation
UI Business Data Exceptions Microsoft Ignite 2015 2/19/2019 8:28 AM © 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
API First Focus on your function Make your UI use your API UI API Business Data
API Second? Expose your Business layer Refactor or add a layer UI Expose your Business layer Refactor or add a layer Make your UI use your API API Data Business
Exposing your API There are plenty of options… but HTTP is easy Self-hosted endpoints – OWIN, Nancy, ASP.NET 5 PM> Install-Package Microsoft.Owin.SelfHost PM> Install-Package Nancy.Owin
Types of Web APIs HTTP/RPC REST HATEOAS Remote Procedure Call Method calls over HTTP Request-response REST REpresentational State Transfer Resource-based URIs HTTP Verbs Stateless HATEOAS Hypermedia As The Engine Of Application State REST + links Self-describing
HTTP/RPC https://api.flickr.com/services/rest/?method=flickr.photos.search&text=ignite&api_key=xxx
REST https://api.spotify.com/v1/artists/1QxaPWG1POM8Ul6WwsHq4y
HATEOAS https://api.github.com /emojis
Be pragmatic
What to include? CRUD for Resources + Sensible functions Be pragmatic POST, GET, PUT, DELETE /api/customers/1 /api/customers/1/addresses /api/customers/1?includeDetail=true /api/customers/1?detailLevel=2 Be pragmatic Use separate classes
Other options OData? GraphQL? /api/Customers(1)/Orders?$filter='Total gt 10000'&$take=5&$orderby=Total,Date desc GraphQL?
Other things that might hurt Long-running Tasks Security Versioning Caching Content negotiation
Architecture The Principle of Least Surprise The Pit of Success Be conservative in what you send, liberal in what you accept
Architecture Consistent URIs /api/customers/1 /api/order/1 /api/customers?top=5 /api/orders/top?count=5
Architecture Consistent objects /api/customers/1 /api/customers
Let’s make one
Why is an API a good thing? Implementation Demo Microsoft Ignite 2015 2/19/2019 8:28 AM Why is an API a good thing? Implementation Demo © 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Thankyou Damian Brady Octopus Deploy @damovisa | @octopusdeploy
Complete your session evaluation on My Ignite for your chance to win one of many daily prizes.
Continue your Ignite learning path Microsoft Ignite 2015 2/19/2019 8:28 AM Continue your Ignite learning path Visit Microsoft Virtual Academy for free online training visit https://www.microsoftvirtualacademy.com Visit Channel 9 to access a wide range of Microsoft training and event recordings https://channel9.msdn.com/ Head to the TechNet Eval Centre to download trials of the latest Microsoft products http://Microsoft.com/en-us/evalcenter/ © 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.