Skip to content
This repository has been archived by the owner on Jan 4, 2025. It is now read-only.

Commit

Permalink
REST API, scheduled endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll committed Jun 25, 2019
1 parent 3de8ae9 commit adb5d59
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/poshud/dashboard.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ $NavBarLinks = @((New-UDLink -Text "Buy Universal Dashboard" -Url "https://ironm
$Pages = @()
$Pages += . (Join-Path $PSScriptRoot "pages\home.ps1")
$Pages += . (Join-Path $PSScriptRoot "pages\getting-started.ps1")
$Pages += . (Join-Path $PSScriptRoot "pages\rest-apis.ps1")
$Pages += . (Join-Path $PSScriptRoot "pages\scheduled-endpoints.ps1")
$Pages += . (Join-Path $PSScriptRoot "dashboards\azure.ps1")

$Components = @()
Expand Down Expand Up @@ -48,8 +50,8 @@ $Pages += (New-UDComponentPage -Command "Show-UDToast")

$Navigation = New-UDSideNav -Content {
New-UDSideNavItem -Text "Home" -Url "Home" -Icon home
New-UDSideNavItem -SubHeader -Text "Dashboards" -Children {
New-UDSideNavItem -Text "Azure Resources" -Url "Azure" -Icon cloud
New-UDSideNavItem -SubHeader -Text "Sample Dashboards" -Icon chart_line -Children {
New-UDSideNavItem -Text "Azure Resources" -Url "Azure"
}
New-UDSideNavItem -SubHeader -Text "About Universal Dashboard" -Icon question -Children {
New-UDSideNavItem -Text "Getting Started" -Url "Getting-Started"
Expand All @@ -58,11 +60,15 @@ $Navigation = New-UDSideNav -Content {
$Components
}
New-UDSideNavItem -SubHeader -Text "Utilities" -Icon wrench -Children {

New-UDSideNavItem -Text "Modals" -Url "Show-UDModal"
New-UDSideNavItem -Text 'Scheduled Endpoints' -Url 'Scheduled-Endpoints'
New-UDSideNavItem -Text "Toasts" -Url "Show-UDToast"
New-UDSideNavItem -Text 'REST APIs' -Url 'REST-APIs'

}
} -Fixed

$EndpointInitialization = New-UDEndpointInitialization -Function "New-UDComponentExample"
$EndpointInitialization = New-UDEndpointInitialization -Function @("New-UDComponentExample", "New-UDRestApiExample", "New-UDRawExample")

New-UDDashboard -NavbarLinks $NavBarLinks -Title "PowerShell Universal Dashboard" -Pages $Pages -Footer $Footer -Navigation $Navigation -EndpointInitialization $EndpointInitialization
65 changes: 65 additions & 0 deletions src/poshud/pages/rest-apis.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
New-UDPage -Name "REST-APIs" -Endpoint {

$OnlineVersion = 'https://github.com/ironmansoftware/universal-dashboard/blob/master/src/poshud/pages/rest-apis.ps1'

New-UDElement -Tag div -Attributes @{ style = @{ paddingLeft = "20px" }} -Content {
New-UDRow -Columns {
New-UDColumn -Size 12 -Content {
New-UDHeading -Size 3 -Text "REST APIs"
}
}

New-UDRow -Columns {
New-UDButton -Icon github -Text "Edit on GitHub" -OnClick (
New-UDEndpoint -Endpoint {
Invoke-UDRedirect -Url $ArgumentList[0] -OpenInNewWindow
} -ArgumentList $OnlineVersion
) -BackgroundColor 'white' -FontColor 'black'
}

New-UDRow -Columns {
New-UDColumn -Size 12 -Content {
New-UDHeading -Size 5 -Text "You can define REST APIs to allow herrogenous systems to interact with PowerShell over HTTP."
}
}

New-UDElement -tag 'hr'

New-UDRow -Columns {
New-UDColumn -Size 12 -Content {
New-UDHeading -Size 4 -Text "Examples"
}
}

New-UDRow -Columns {
New-UDColumn -Size 12 -Content {
New-UDRestApiExample -Name "Return Data" -Description "Creates a basic GET endpoint that returns data." -Code "New-UDEndpoint -Url '/data' -Endpoint { 'Hello, World!' } " -Invocation "Invoke-RestMethod http://localhost:10001/api/data"
}
}

New-UDRow -Columns {
New-UDColumn -Size 12 -Content {
New-UDRestApiExample -Name "Filter Data" -Description "Filter data using route variables." -Code "New-UDEndpoint -Url '/data/:filter' -Endpoint { param(`$filter) @(1,2,3) | Where-Object { `$_ -eq `$filter } } " -Invocation "Invoke-RestMethod http://localhost:10001/api/data/1"
}
}

New-UDRow -Columns {
New-UDColumn -Size 12 -Content {
New-UDRestApiExample -Name "Filter Data with query string parameters" -Description "Filter data using query string parameters." -Code "New-UDEndpoint -Url '/queryData' -Endpoint { param(`$filter) @(1,2,3) | Where-Object { `$_ -eq `$filter } } " -Invocation "Invoke-RestMethod http://localhost:10001/api/queryData?filter=1"
}
}


New-UDRow -Columns {
New-UDColumn -Size 12 -Content {
New-UDRestApiExample -Name "Send Data to the Server" -Description "Sends data to the server via the body" -Code "New-UDEndpoint -Method POST -Url '/data' -Endpoint { param(`$Body) `$Body } " -Invocation "Invoke-RestMethod http://localhost:10001/api/data -Method POST -Body 'Echo'"
}
}

New-UDRow -Columns {
New-UDColumn -Size 12 -Content {
New-UDRestApiExample -Name "Send Data via route variables" -Description "Uses route variables to send data to the endpoint on the server" -Code "New-UDEndpoint -Method POST -Url '/data/:variable' -Endpoint { param(`$variable) `$variable } " -Invocation "Invoke-RestMethod http://localhost:10001/api/data/echo -Method POST"
}
}
}
}
40 changes: 40 additions & 0 deletions src/poshud/pages/scheduled-endpoints.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
New-UDPage -Name "Scheduled-Endpoints" -Endpoint {

$OnlineVersion = 'https://github.com/ironmansoftware/universal-dashboard/blob/master/src/poshud/pages/scheduled-endpoints.ps1'

New-UDElement -Tag div -Attributes @{ style = @{ paddingLeft = "20px" }} -Content {
New-UDRow -Columns {
New-UDColumn -Size 12 -Content {
New-UDHeading -Size 3 -Text "Scheduled Endpoints"
}
}

New-UDRow -Columns {
New-UDButton -Icon github -Text "Edit on GitHub" -OnClick (
New-UDEndpoint -Endpoint {
Invoke-UDRedirect -Url $ArgumentList[0] -OpenInNewWindow
} -ArgumentList $OnlineVersion
) -BackgroundColor 'white' -FontColor 'black'
}

New-UDRow -Columns {
New-UDColumn -Size 12 -Content {
New-UDHeading -Size 5 -Text "Scheduled endpoints allow you to schedule actions to be taken on an interval. This is similar to a task scheduler but can interact with features of Universal Dashboard."
}
}

New-UDElement -tag 'hr'

New-UDRow -Columns {
New-UDColumn -Size 12 -Content {
New-UDHeading -Size 4 -Text "Examples"
}
}

New-UDRow -Columns {
New-UDColumn -Size 12 -Content {
New-UDRawExample -Title 'Scheduled every 10 minutes' -Description "Runs the scheduled endpoint every ten minutes." -Code "New-UDEndpoint -Schedule (New-UDEndpointSchedule -Every 10 -Minute) -Endpoint { `$Cache:Processes = Get-Process }"
}
}
}
}
72 changes: 72 additions & 0 deletions src/poshud/utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,77 @@ function New-UDComponentExample {
}
}

New-UDElement -tag 'hr'
}

function New-UDRestApiExample {
param(
$Name,
$Description,
$Code,
$Invocation
)

New-UDHeading -Size 4 -Text $Name
New-UDHeading -Size 5 -Text $Description

New-UDTabContainer -Tabs {
New-UDTab -Text "Code" -Content {
New-UDElement -Tag 'div' -Attributes @{
style = @{
padding = '30px'
background = '#f8f8f8'
}
} -Content {
New-UDElement -tag pre -Content {
$Code
Invoke-Expression $Code | Out-Null
}
}
}
New-UDTab -Text "Try It" -Content {
New-UDElement -Tag 'div' -Attributes @{
style = @{
padding = '30px'
background = '#f8f8f8'
}
} -Content {
New-UDElement -tag pre -Content {
$Invocation
}
}
}
}

New-UDElement -tag 'hr'
}


function New-UDRawExample {
param(
$Name,
$Description,
$Code
)

New-UDHeading -Size 4 -Text $Name
New-UDHeading -Size 5 -Text $Description

New-UDTabContainer -Tabs {
New-UDTab -Text "Code" -Content {
New-UDElement -Tag 'div' -Attributes @{
style = @{
padding = '30px'
background = '#f8f8f8'
}
} -Content {
New-UDElement -tag pre -Content {
$Code
Invoke-Expression $Code | Out-Null
}
}
}
}

New-UDElement -tag 'hr'
}

0 comments on commit adb5d59

Please sign in to comment.