toenuff / flancy

A micro web framework for Windows PowerShell
MIT License
189 stars 21 forks source link

Change Webschema to be a DSL #27

Closed toenuff closed 8 years ago

toenuff commented 8 years ago

@adamdriscoll put together a prototype of a DSL instead of a hash Implemented here in a busted branch: https://github.com/adamdriscoll/flancy/blob/dsl/flancy.psm1

This is a nice way to visualize and control what is allowed. Once this is implemented, we can do staticfiles and staticdirs as a keyword as well. It also feels a lot more like flask.

Adam documented how it would be used here: https://github.com/adamdriscoll/flancy/blob/dsl/example.ps1

basically:

new-flancy -url $url -Authentication Token -webschema @(
    Get '/' { "Welcome to Flancy!" }

    Get '/Process' { Get-Process | select name, id, path | ConvertTo-Json }

    Post '/Process' { 
        $processname = (new-Object System.IO.StreamReader @($Request.Body, [System.Text.Encoding]::UTF8)).ReadToEnd()
        Start-Process $processname
    }

    Get '/process/{name}' { get-process $parameters.name |convertto-json -depth 1 }

    Get '/prettyprocess' { Get-Process | ConvertTo-HTML name, id, path }

    Post '/authenticate' { 
        New-Token -UserName "Adam" -Context $Context
    }
)
toenuff commented 8 years ago

I'm working on porting this into the devel branch without the token stuff since that is still broken

adamdriscoll commented 8 years ago

Thanks. My fork is all jacked right now....