How to create an endpoint that takes value input and returns data based on input?


Just started looking into Powershell Universal, and it looks extremely useful. I have a use case that I so far haven’t been able to find any pointers to in the docs or samples.

I have a powershell script that currently takes a value as input through read-host (let’s say “customer name”). The script then queries a backend system for details related to that customer name, and returns the values via write-host.

How would I go about converting this routine to an endpoint query in PSU?

I’ve gotten as far as to creating my endpoint with url “customer” and method “GET”, but I’m struggling to further build the query and return results,

Do you perhaps mean the “Variable URL” functionality of the Endpoints, as mentioned in the documentation found at: Endpoints - PowerShell Universal

Where your example could be something like:

New-PSUEndpoint -Url '/:customerName' -Method 'GET' -Endpoint {
    function Invoke-FunctionThatQueriesYourBackendSystem {
        # here be dragons
    Invoke-FunctionThatQueriesYourBackendSystem -SomeParameter $customerName

Which would then be used as:

Invoke-RestMethod https://your-universal-address/theCustomerName

and will return whatever your Invoke-FunctionThatQueriesYourBackendSystem function returns, perhaps?