Skip to content

Commit 7fa2a7c

Browse files
StartAutomatingStartAutomating
authored andcommitted
Adding REST transpiler (#114)
1 parent c9f19e1 commit 7fa2a7c

File tree

1 file changed

+183
-0
lines changed

1 file changed

+183
-0
lines changed

docs/Rest.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
2+
Rest
3+
----
4+
### Synopsis
5+
Generates PowerShell to talk to a REST api.
6+
7+
---
8+
### Description
9+
10+
Generates PowerShell that communicates with a REST api.
11+
12+
---
13+
### Examples
14+
#### EXAMPLE 1
15+
```PowerShell
16+
{
17+
function Get-Sentiment {
18+
[Rest("http://text-processing.com/api/sentiment/",
19+
ContentType="application/x-www-form-urlencoded",
20+
Method = "POST",
21+
BodyParameter="Text",
22+
ForeachOutput = {
23+
$_ | Select-Object -ExpandProperty Probability -Property Label
24+
}
25+
)]
26+
param()
27+
}
28+
} | .>PipeScript | Set-Content .\Get-Sentiment.ps1
29+
```
30+
31+
#### EXAMPLE 2
32+
```PowerShell
33+
Invoke-PipeScript {
34+
[Rest("http://text-processing.com/api/sentiment/",
35+
ContentType="application/x-www-form-urlencoded",
36+
Method = "POST",
37+
BodyParameter="Text",
38+
ForeachOutput = {
39+
$_ | Select-Object -ExpandProperty Probability -Property Label
40+
}
41+
)]
42+
param()
43+
} -Parameter @{Text='wow!'}
44+
```
45+
46+
#### EXAMPLE 3
47+
```PowerShell
48+
{
49+
[Rest("https://api.github.com/users/{username}/repos",
50+
QueryParameter={"type", "sort", "direction", "page", "per_page"}
51+
)]
52+
param()
53+
} | .>PipeScript
54+
```
55+
56+
#### EXAMPLE 4
57+
```PowerShell
58+
Invoke-PipeScript {
59+
[Rest("https://api.github.com/users/{username}/repos",
60+
QueryParameter={"type", "sort", "direction", "page", "per_page"}
61+
)]
62+
param()
63+
} -UserName StartAutomating
64+
```
65+
66+
#### EXAMPLE 5
67+
```PowerShell
68+
{
69+
[Rest("http://text-processing.com/api/sentiment/",
70+
ContentType="application/x-www-form-urlencoded",
71+
Method = "POST",
72+
BodyParameter={@{
73+
Text = '
74+
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
75+
[string]
76+
$Text
77+
'
78+
}})]
79+
param()
80+
} | .>PipeScript
81+
```
82+
83+
---
84+
### Parameters
85+
#### **ScriptBlock**
86+
87+
The ScriptBlock.
88+
If not empty, the contents of this ScriptBlock will preceed the REST api call.
89+
90+
91+
92+
|Type |Requried|Postion|PipelineInput |
93+
|-------------------|--------|-------|--------------|
94+
|```[ScriptBlock]```|false |named |true (ByValue)|
95+
---
96+
#### **RESTEndpoint**
97+
98+
One or more REST endpoints. This endpoint will be parsed for REST variables.
99+
100+
101+
102+
|Type |Requried|Postion|PipelineInput|
103+
|----------------|--------|-------|-------------|
104+
|```[String[]]```|true |1 |false |
105+
---
106+
#### **ContentType**
107+
108+
The content type. If provided, this parameter will be passed to the -InvokeCommand.
109+
110+
111+
112+
|Type |Requried|Postion|PipelineInput|
113+
|--------------|--------|-------|-------------|
114+
|```[String]```|false |named |false |
115+
---
116+
#### **Method**
117+
118+
The method. If provided, this parameter will be passed to the -InvokeCommand.
119+
120+
121+
122+
|Type |Requried|Postion|PipelineInput|
123+
|--------------|--------|-------|-------------|
124+
|```[String]```|false |named |false |
125+
---
126+
#### **InvokeCommand**
127+
128+
The invoke command. This command _must_ have a parameter -URI.
129+
130+
131+
132+
|Type |Requried|Postion|PipelineInput|
133+
|--------------|--------|-------|-------------|
134+
|```[String]```|false |named |false |
135+
---
136+
#### **InvokeParameterVariable**
137+
138+
The name of a variable containing additional invoke parameters.
139+
By default, this is 'InvokeParams'
140+
141+
142+
143+
|Type |Requried|Postion|PipelineInput|
144+
|--------------|--------|-------|-------------|
145+
|```[String]```|false |named |false |
146+
---
147+
#### **BodyParameter**
148+
149+
A dictionary or list of parameters for the body.
150+
151+
152+
153+
|Type |Requried|Postion|PipelineInput|
154+
|----------------|--------|-------|-------------|
155+
|```[PSObject]```|false |named |false |
156+
---
157+
#### **QueryParameter**
158+
159+
A dictionary or list of query parameters.
160+
161+
162+
163+
|Type |Requried|Postion|PipelineInput|
164+
|----------------|--------|-------|-------------|
165+
|```[PSObject]```|false |named |false |
166+
---
167+
#### **ForEachOutput**
168+
169+
A script block to be run on each output.
170+
171+
172+
173+
|Type |Requried|Postion|PipelineInput|
174+
|-------------------|--------|-------|-------------|
175+
|```[ScriptBlock]```|false |named |false |
176+
---
177+
### Syntax
178+
```PowerShell
179+
Rest [-ScriptBlock <ScriptBlock>] [-RESTEndpoint] <String[]> [-ContentType <String>] [-Method <String>] [-InvokeCommand <String>] [-InvokeParameterVariable <String>] [-BodyParameter <PSObject>] [-QueryParameter <PSObject>] [-ForEachOutput <ScriptBlock>] [<CommonParameters>]
180+
```
181+
---
182+
183+

0 commit comments

Comments
 (0)