是否有用于URI模板解析的本地PowerShell库?

问题描述 投票:0回答:1

我正在使用Octopus REST API,我想充分利用Octopus REST API中提供的HATEOAS links,其中一些使用URI Templates

[我在Octopus论坛here上找到了一个相当老的帖子,但我想知道是否有4年多的时间,如果在PowerShell中解析Uri模板是否有更好的解决方案。

如果没有,我可以使用论坛帖子中列出的.NET Uri模板解析包。

powershell rest uri octopus-deploy hateoas
1个回答
0
投票

所以我找不到任何本机解决方案,但是我将分享一个实现Resta.UriTemplates的示例。


# Example adapted from: https://github.com/a7b0/uri-templates#examples

Install-Package Resta.UriTemplates -Version 1.3.0

# Import the Resta.UriTemplates assembly
$Path = '.\Resta.UriTemplates.1.3.0\lib\netstandard2.0\Resta.UriTemplates.dll'
Add-Type -Path $Path -PassThru | Select-Object -ExpandProperty Assembly | Select-Object -ExpandProperty FullName -Unique
# Returns: Resta.UriTemplates, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null

$template = [Resta.UriTemplates.UriTemplate]'http://example.org/{area}/news{?type,count}'

$dict = New-Object 'system.collections.generic.dictionary[string,object]'
$dict["area"] = "world"
$dict["type"] = "actual"
$dict["count"] = "10"

$template.Resolve($dict)
# Returns: http://example.org/world/news?type=actual&count=10
© www.soinside.com 2019 - 2024. All rights reserved.