cmdlet parser
affieuk opened this issue · 3 comments
What's the possibility of having a cmdlet parser from an allowed list that Polaris read's those cmdlets, figures out the parameters and output of said cmdlet and then auto-creates a route with the relevant method.
e.g.
Get-Item
Parses that as:
Method: Get
Query Params: [string]$Path, [string]$Filter, [string[]]Include, etc
Output: one of the following as JSON
System.IO.FileInfo
System.Boolean
System.String
System.IO.FileInfo
System.IO.DirectoryInfo
This looks like the reverse of https://github.com/PowerShell/PSSwagger in a way!
it's an interesting idea. I'm guessing the route that would be auto-generated would look something like:
{
param($request, $response)
$result = Get-Item -Path $request.query.path -Filter $request.query.filter -Include $request.query.include
$response.Json(($result | ConvertTo-Json))
}
The script block would also need to import whatever module the cmdlet comes from.
I like it! I've got a few higher pri features I want to address (like the body posting for example) but I really like your idea. (always looking for contributions 😄 )
Any chance I can have some feedback on this:
Import-WebRoute
The function name needs to change, doesn't seem right. Also need to figure out how to map http verbs to PowerShell verbs
@TylerLeonhardt if I'm off here let me know but after reviewing the code in the PR and the suggestions I think this would be better viewed as an awesome project to build on top of Polaris. This is definitely something I would be interested in seeing but if we were to adopt this into the code base I think we would be moving away from being "a simple PowerShell web framework" and into "a tool for exposing cmdlets as APIs".
@TylerLeonhardt if you agree with that thought I think we can close this issue out.
That being said let me know if you start a project up on this @affieuk. I would definitely be interested in contributing. We could also generate a swagger json file pretty easily and display a little swagger ui for people to play around with the API relatively easily. Also it would be interesting to figure out a method for implementing the piping system although that might fit better in an RPC / RFC style API instead of a REST design pattern.