Tulsa TechFest 2016
Using REST w/VSTS & TFS
Friday, August 5th
Jeff Bramwell
VP – Enterprise Architecture, Farm Credit Services of America
MVP - Visual Studio & Development Technologies
jeff@moonspace.net ::: @jbramwell
Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!
Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!
Agenda
• History of APIs
• Why Extend?
• HTTP Methods
• REST Debugging Tools
• Authentication with VSTS/TFS
• HttpClient vs. HttpWebRequest
• Convert JSON to Classes
• Summary
History
• TFS 2005, 2008
• ASMX
• TFS 2010, 2012, 2013, 2015
• WCF Services
• TFS 2015/VSTS
• REST APIs
• TFS Object Model
• All Versions
Add support for custom processes/workflows
Audit users and related permissions
Batch push/commit/pull for files
Add ability to manage work item tags
Why Extend?
Add UI Elements
Builds
Security
Version Control
Examples
The options are limitless!What Else?
Available REST APIs
• Build 1.0
• Build 2.0
• Cloud Load Test
• Code Policy
• Dashboards and Widgets
• Git
• Packaging
• Projects and Teams
• Queues
• Release
• Service Hooks
• Team Room
• Test Management
• Version Control
• Work (Agile)
• Work Item Tracking
HTTP Methods
• Get
• Retrieve one or more resources
• POST
• Create a new resource
• PUT
• Update a resource
• PATCH
• Also update a resource (and more)
• DELETE
• Delete a resource
HTTP Debugging Tools
• Several Options:
• Telerik Fiddler
• Postman (for Chrome)
• HttpRequester (for Firefox)
• RESTClient (for Firefox)
• REST Easy (for Firefox)
• Many Others…
Authentication
Three approaches:
1. Basic Authentication
2. OAuth
3. Personal Access Tokens (PAT)
DEMO
Creating a Personal Access Token
DEMO
Calling an API: Getting a list of Builds
Sprinkle in Some C#
Multiple Approaches:
• Hand-code everything, including POCOs
• Make use of http://json2csharp.com/ to create initial POCOs
• Do the same thing as above but with Visual Studio 2015
• Use a Fiddler extension such as Fiddler Request To Code
DEMO
Let’s Generate Some Code!
HttpClient vs. HttpWebRequest
• HttpClient is built on top of HttpWebRequest
• HttpClient is generally easier to use and requires less code
• A single HttpClient instance can service multiple calls
• To multiple servers/hosts
• Support for await command
• Long story short…
• HttpClient for most tasks
• HttpWebRequest when you need more control
DEMO
Convert to HttpClient
Using the POCOs
• Essentially involves deserialization
• Quickest method: Use Newtonsoft.JSON NuGet package
• Will map JSON elements to class properties for you
DEMO
Now, let’s tie in the entity classes
Summary
• VSTS/TFS can be extended via REST APIs
• Very powerful
• Multiple ways to interact with and/or debug APIs
• Can be extended from multiple languages including C#, PowerShell,
JavaScript, etc.
• Not all WCF/TFSOM methods exposed via REST yet, but getting closer
More Examples
VSTS Tools
• Command-line utilities
• Custom build tasks (packaged as an extension)
• Source available on GitHub:
• https://github.com/jbramwell/VSTS-Tools
• Can download from Visual Studio Marketplace:
• https://marketplace.visualstudio.com/items?itemName=moons
pace-labs-llc.vsts-tools-build-extensions
Extending TFS and VSTS eBook
• https://leanpub.com/tfsapibook
Questions? More
Information?
REST API Reference for VS Team Services and TFS
• http://bit.ly/VSTSRESTAPI
Brian Harry (Product Unit Manager for TFS)
• https://blogs.msdn.microsoft.com/bharry/
My Blog
• http://blog.devmatter.com
Code/Extension Examples
• https://github.com/jbramwell/VSTS-Tools
Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!
Your input is important!
http://TulsaTechFest.com

Using REST with VSTS and TFS

  • 1.
    Tulsa TechFest 2016 UsingREST w/VSTS & TFS Friday, August 5th Jeff Bramwell VP – Enterprise Architecture, Farm Credit Services of America MVP - Visual Studio & Development Technologies jeff@moonspace.net ::: @jbramwell
  • 2.
    Tulsa TechFest 2016| Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!
  • 3.
    Tulsa TechFest 2016| Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!
  • 4.
    Agenda • History ofAPIs • Why Extend? • HTTP Methods • REST Debugging Tools • Authentication with VSTS/TFS • HttpClient vs. HttpWebRequest • Convert JSON to Classes • Summary
  • 5.
    History • TFS 2005,2008 • ASMX • TFS 2010, 2012, 2013, 2015 • WCF Services • TFS 2015/VSTS • REST APIs • TFS Object Model • All Versions
  • 6.
    Add support forcustom processes/workflows Audit users and related permissions Batch push/commit/pull for files Add ability to manage work item tags Why Extend? Add UI Elements Builds Security Version Control Examples The options are limitless!What Else?
  • 7.
    Available REST APIs •Build 1.0 • Build 2.0 • Cloud Load Test • Code Policy • Dashboards and Widgets • Git • Packaging • Projects and Teams • Queues • Release • Service Hooks • Team Room • Test Management • Version Control • Work (Agile) • Work Item Tracking
  • 8.
    HTTP Methods • Get •Retrieve one or more resources • POST • Create a new resource • PUT • Update a resource • PATCH • Also update a resource (and more) • DELETE • Delete a resource
  • 9.
    HTTP Debugging Tools •Several Options: • Telerik Fiddler • Postman (for Chrome) • HttpRequester (for Firefox) • RESTClient (for Firefox) • REST Easy (for Firefox) • Many Others…
  • 10.
    Authentication Three approaches: 1. BasicAuthentication 2. OAuth 3. Personal Access Tokens (PAT)
  • 11.
  • 12.
    DEMO Calling an API:Getting a list of Builds
  • 13.
    Sprinkle in SomeC# Multiple Approaches: • Hand-code everything, including POCOs • Make use of http://json2csharp.com/ to create initial POCOs • Do the same thing as above but with Visual Studio 2015 • Use a Fiddler extension such as Fiddler Request To Code
  • 14.
  • 15.
    HttpClient vs. HttpWebRequest •HttpClient is built on top of HttpWebRequest • HttpClient is generally easier to use and requires less code • A single HttpClient instance can service multiple calls • To multiple servers/hosts • Support for await command • Long story short… • HttpClient for most tasks • HttpWebRequest when you need more control
  • 16.
  • 17.
    Using the POCOs •Essentially involves deserialization • Quickest method: Use Newtonsoft.JSON NuGet package • Will map JSON elements to class properties for you
  • 18.
    DEMO Now, let’s tiein the entity classes
  • 19.
    Summary • VSTS/TFS canbe extended via REST APIs • Very powerful • Multiple ways to interact with and/or debug APIs • Can be extended from multiple languages including C#, PowerShell, JavaScript, etc. • Not all WCF/TFSOM methods exposed via REST yet, but getting closer
  • 20.
    More Examples VSTS Tools •Command-line utilities • Custom build tasks (packaged as an extension) • Source available on GitHub: • https://github.com/jbramwell/VSTS-Tools • Can download from Visual Studio Marketplace: • https://marketplace.visualstudio.com/items?itemName=moons pace-labs-llc.vsts-tools-build-extensions Extending TFS and VSTS eBook • https://leanpub.com/tfsapibook
  • 21.
    Questions? More Information? REST APIReference for VS Team Services and TFS • http://bit.ly/VSTSRESTAPI Brian Harry (Product Unit Manager for TFS) • https://blogs.msdn.microsoft.com/bharry/ My Blog • http://blog.devmatter.com Code/Extension Examples • https://github.com/jbramwell/VSTS-Tools
  • 22.
    Tulsa TechFest 2016| Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions! Your input is important! http://TulsaTechFest.com

Editor's Notes

  • #6 REST APIs do not yet have full parity with WCF services/TFS Object Model There is also a Java SDK as well as an unsupported OData API
  • #7 Add custom version capabilities to assemblies/NuGet packages as part of build process Ensure projects have permissions configured based on desired guidance Make mass changes to code across multiple projects – e.g. configuration file updates Rename or delete tags
  • #8 As of August, 2016
  • #9 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)
  • #10 Fiddler was acquired by Telerik back in 2012 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)
  • #11 If using Basic Authentication, ensure SSL is enabled. https://www.visualstudio.com/en-us/docs/integrate/get-started/auth/overview PATs are simple to implement https://www.visualstudio.com/en-us/docs/integrate/get-started/auth/oauth OAuth provides a familiar user experience for most users – rather than requiring them to create and provide a PAT https://www.visualstudio.com/en-us/docs/integrate/get-started/auth/overview
  • #14 HttpWebRequest came first – gives you full control over the web request but tends to require more code HttpClient is built on top of HttpWebRequest but requires much less code (and could also be a tad slower) Supports async calls Requires .NET 4.5 (or higher)
  • #16 HttpWebRequest came first – gives you full control over the web request but tends to require more code HttpClient is built on top of HttpWebRequest but requires much less code (and could also be a tad slower) Supports async calls Requires .NET 4.5 (or higher)
  • #21 HttpWebRequest came first – gives you full control over the web request but tends to require more code HttpClient is built on top of HttpWebRequest but requires much less code (and could also be a tad slower) Supports async calls Requires .NET 4.5 (or higher)