en-US/about_PSApi.help.txt

TOPIC
    about_PSApi
 
SHORT DESCRIPTION
    Provides an overall description of the PSApi module and how to use it. The
    information below is an abbreviated version of the information found at
    https://github.com/NotNotWrongUsually/PSApi
 
LONG DESCRIPTION
    The PSApi module takes a function from your current session and publishes it
    as a webservice. Using defaults your command will be exposed at:
 
    http://localhost/PSApi/<your-command>
 
    Using the parameters for the command you can modify the path, port, logging
    location etc. Refer to the help on Publish-Command for more information
    about the options.
 
    Any parameters for a published command can be supplied in the url query
    string.
 
RETURN TYPES
     
    [XML]
    is turned into a string by using the OuterXml property of the object.
 
    [System.Drawing.Image]
    will be converted to png format and presented in the browser.
 
    [Microsoft.Powershell.Commands.HtmlWebResponseObject]
    will be turned into a string by using the content property, so only the
    actual html is passed on.
 
    [String]
    will be sent with a content type of text/html. For an exception refer to the
    note on JSON below.
 
    JSON: There is no specific JSON type. Even content created with
    ConvertTo-Json is just listed as [String]. To present the correct
    content-type for JSON a test is performed on [String] objects. If an object
    can be be piped to ConvertFrom-Json without raising an exception the
    content-type will be set to application/json. The Test-Json cmdlet is not
    used for this as it appears utterly broken from testing.
 
    [Everything else]
    Anything that is not one of the above types will be stringified with the
    Out-String cmdlet and set to a content-type of text/plain. Notably this
    means that most things will look exactly like they do in the Powershell
    console.
 
EXAMPLES
 
    EXAMPLE 1:
 
    Creating a simple monitoring API showing the processes using most CPU time
  
    PS > function Get-HighCpuConsumers ($Top=5) {
    >> Get-Process | Sort-Object CPU -Descending |
    >> Select-Object Name, CPU, StartTime -First $Top |
    >> ConvertTo-Json
    >> }
 
    PS > Publish-Command Get-HighCpuConsumers
 
    Going to
     
    http://myhostname/PSApi/Get-HighCpuConsumers
     
    or alternatively
 
    http://myhostname/PSApi/Get-HighCpuConsumers?number=<x>
     
    Will display JSON with the relevant information for the machine.
 
    EXAMPLE 2:
 
    Serving an image
 
    PS > function Get-Image {
    >> New-Object System.Drawing.Bitmap -ArgumentList "C:\some_picture.jpg"
    >> }
 
    Going to http://myhostname/PSApi/Get-Image will display the picture.
 
SEE ALSO
    Help Publish-Command for more examples