22
Tulsa TechFest 2016 Using REST w/VSTS & TFS Friday, August 5 th Jeff Bramwell VP – Enterprise Architecture, Farm Credit Services of America MVP - Visual Studio & Development Technologies [email protected] ::: @jbramwell

Using REST with VSTS and TFS

Embed Size (px)

Citation preview

Orange Earth

Tulsa TechFest 2016Using REST w/VSTS & TFSFriday, August 5th

Jeff BramwellVP Enterprise Architecture, Farm Credit Services of AmericaMVP - Visual Studio & Development [email protected] ::: @jbramwell

Please Be Courteous!

Please be courteous to your fellow attendeesandset your phones to vibrate or silent mode!

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions! Please help us!Thank our Sponsors:

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

8/5/2016 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.3

AgendaHistory of APIsWhy Extend?HTTP MethodsREST Debugging ToolsAuthentication with VSTS/TFSHttpClient vs. HttpWebRequestConvert JSON to ClassesSummary

2006

HistoryTFS 2005, 2008ASMXTFS 2010, 2012, 2013, 2015WCF ServicesTFS 2015/VSTSREST APIsTFS Object ModelAll Versions

REST APIs do not yet have full parity with WCF services/TFS Object ModelThere is also a Java SDK as well as an unsupported OData API

5

Add support for custom processes/workflows Audit users and related permissionsBatch push/commit/pull for filesAdd ability to manage work item tagsWhy Extend?Add UI ElementsBuildsSecurityVersion ControlExamplesThe options are limitless!What Else?

Add custom version capabilities to assemblies/NuGet packages as part of build processEnsure projects have permissions configured based on desired guidanceMake mass changes to code across multiple projects e.g. configuration file updatesRename or delete tags6

Available REST APIsBuild 1.0Build 2.0Cloud Load TestCode PolicyDashboards and WidgetsGitPackagingProjects and Teams

QueuesReleaseService HooksTeam RoomTest ManagementVersion ControlWork (Agile)Work Item Tracking

As of August, 20167

HTTP Methods

GetRetrieve one or more resourcesPOSTCreate a new resourcePUTUpdate a resourcePATCHAlso update a resource (and more)DELETEDelete a resource

Talk about issues with using PUT when contracts have changed (e.g. adding a new field that calling clients are unaware of and the new field ends up being nulled out on updates)8

HTTP Debugging ToolsSeveral Options:Telerik FiddlerPostman (for Chrome)HttpRequester (for Firefox)RESTClient (for Firefox)REST Easy (for Firefox)Many Others

Fiddler was acquired by Telerik back in 2012Talk about issues with using PUT when contracts have changed (e.g. adding a new field that calling clients are unaware of and the new field ends up being nulled out on updates)9

AuthenticationThree approaches:Basic AuthenticationOAuthPersonal Access Tokens (PAT)

If using Basic Authentication, ensure SSL is enabled.https://www.visualstudio.com/en-us/docs/integrate/get-started/auth/overviewPATs are simple to implementhttps://www.visualstudio.com/en-us/docs/integrate/get-started/auth/oauthOAuth provides a familiar user experience for most users rather than requiring them to create and provide a PAThttps://www.visualstudio.com/en-us/docs/integrate/get-started/auth/overview10

DemoCreating a Personal Access Token

DemoCalling an API: Getting a list of Builds

Sprinkle in Some C#Multiple Approaches:Hand-code everything, including POCOsMake use of http://json2csharp.com/ to create initial POCOsDo the same thing as above but with Visual Studio 2015Use a Fiddler extension such as Fiddler Request To Code

HttpWebRequest came first gives you full control over the web request but tends to require more codeHttpClient is built on top of HttpWebRequest but requires much less code (and could also be a tad slower)Supports async callsRequires .NET 4.5 (or higher)

13

DemoLets Generate Some Code!

HttpClient vs. HttpWebRequestHttpClient is built on top of HttpWebRequestHttpClient is generally easier to use and requires less codeA single HttpClient instance can service multiple callsTo multiple servers/hostsSupport for await commandLong story shortHttpClient for most tasksHttpWebRequest when you need more control

HttpWebRequest came first gives you full control over the web request but tends to require more codeHttpClient is built on top of HttpWebRequest but requires much less code (and could also be a tad slower)Supports async callsRequires .NET 4.5 (or higher)

15

DemoConvert to HttpClient

Using the POCOsEssentially involves deserializationQuickest method: Use Newtonsoft.JSON NuGet packageWill map JSON elements to class properties for you

DemoNow, lets tie in the entity classes

SummaryVSTS/TFS can be extended via REST APIsVery powerfulMultiple ways to interact with and/or debug APIsCan be extended from multiple languages including C#, PowerShell, JavaScript, etc.Not all WCF/TFSOM methods exposed via REST yet, but getting closer

More ExamplesVSTS ToolsCommand-line utilitiesCustom build tasks (packaged as an extension)Source available on GitHub:https://github.com/jbramwell/VSTS-ToolsCan download from Visual Studio Marketplace:https://marketplace.visualstudio.com/items?itemName=moonspace-labs-llc.vsts-tools-build-extensions

Extending TFS and VSTS eBookhttps://leanpub.com/tfsapibook

HttpWebRequest came first gives you full control over the web request but tends to require more codeHttpClient is built on top of HttpWebRequest but requires much less code (and could also be a tad slower)Supports async callsRequires .NET 4.5 (or higher)

20

Questions? More Information?

REST API Reference for VS Team Services and TFShttp://bit.ly/VSTSRESTAPI Brian Harry (Product Unit Manager for TFS)https://blogs.msdn.microsoft.com/bharry/My Bloghttp://blog.devmatter.com Code/Extension Exampleshttps://github.com/jbramwell/VSTS-Tools

Please Complete An Evaluation FormYour input is important!You can access Evaluation Forms at:http://TulsaTechFest.com

Fill them out!

You can win additional prizes!

Like a $50 Best Buy Gift Card!!

Winner drawn Midnight, Sun Aug 7th!

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

8/5/2016 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.22