One concept that I’ve been thinking about for a long time is the ability to automatically generate REST APIs based on Universal Dashboard for existing PowerShell modules. It just seems like a lot of ceremony to wrap existing functions in New-UDEndpoint calls. Because PowerShell is inherently descriptive of the commands that it surfaces, it’s easy to look up the metadata about a command and generate the necessary code without having to do it yourself.
Today, I’m releasing the very early stage of a project I call OutRest. At this point, it’s more of a concept than an actual tool. It allows you to automatically create REST APIs from your existing modules and functions using Universal Dashboard. It exposes a single command to generate REST API endpoints.
You can install OutRest from the Gallery:
The main features of OutRest is that is looks at the parameter sets of a command or advanced function and determines the mandatory parameters for that command. It then creates a route based on those sets. For example, Get-Service has three parameter sets. The first parameter set doesn’t require any parameters so the route would become this.
Invoking this API would return all the services as JSON. Using Invoke-RestMethod would convert each of the services back to a PSCustomObject you can then use in your client scripts.
The second parameter set requires a DisplayName parameter, the route then becomes this.
OutRest automatically binds the mandatory parameters to the command when it invokes it so it calls the correct parameter set. Invoking this API would return a single service object.
OutRest also supports binding optional parameters via query string parameters. For example, if we wanted to use the Include parameter of Get-Service, we could use the query string parameter and it would only return the fax service.
This was mostly a fun example of what can be done with Universal Dashboard and meta-programming. I’d be curious to gauge interest and probably continue to work on it when I have a chance. I think it’s a great way to quickly generate a REST API without having to learn too much Universal Dashboard.
The source code is available on GitHub. Feel free to throw in issues and PRs if you have some good ideas on how to make this more of a complete solution.