Simple requests

The REST API provided by GitHub may be used to list repositories made available by the PowerShell team.

The API entry point is https://api.github.com as documented in this reference: https://developer.github.com/v3/.

When working with REST, documentation is very important. The manner in which an interface is used is common, but the manner is which it may respond is not (as this is an architectural style, not a strict protocol).

The specific method being called is documented on a different page of the following reference: https://developer.github.com/v3/repos/#list-user-repositories.

The name of the user forms part of the URI; there are no arguments for this method. Therefore, the following command will execute the method and return detailed information about the repositories owned by the PowerShell user (or organization):

Invoke-RestMethod -Uri https://api.github.com/users/powershell/repos  

Windows PowerShell is likely to throw an error relating to SSL/TLS when running this command. This is because the site uses TLS 1.2 whereas, by default, Invoke-RestMethod reaches as far as TLS 1.0. PowerShell Core users should not experience this problem.

This Windows PowerShell problem can be fixed by tweaking the SecurityProtocol property of ServicePointManager as follows:

using namespace System.Net
[ServicePointManager]::SecurityProtocol = [ServicePointManager]::SecurityProtocol -bor 'Tls12'

The bitwise -bor operator is used to add TLS 1.2 to the default list, which includes Ssl3 and Tls. TLS 1.1 (Tls11) may be added in a similar manner if required.

All examples use TLS 1.2

This setting is required for the examples that follow when running Windows PowerShell.

Older versions of Windows may require a patch from Windows Update to gain support for TLS 1.2.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.189.177