代码之家  ›  专栏  ›  技术社区  ›  Muhammad Alkarouri

F#web服务器库

  •  8
  • Muhammad Alkarouri  · 技术社区  · 15 年前

    F#是否有类似于Python中SimpleHTTPServer的web服务器库?

    安装像IIS这样的完整服务器对于我想要的是一种过度的杀伤力,它是一个简单的应用程序,可以使用web浏览器进行查询,有效地使用HTTP作为监视方法。理想情况下,请求 /engines/id/state get_state(engine_id) 我提供的。

    3 回复  |  直到 15 年前
        1
  •  12
  •   Brian    15 年前

    自托管WCF服务并不是一个坏的开始;这里有一个很小的开始:

    open System
    open System.IO 
    // add reference to these two guys, need .NET full (not client profile)
    open System.ServiceModel
    open System.ServiceModel.Web
    
    [<ServiceContract>]
    type MyContract() =
        [<OperationContract>]
        [<WebGet(UriTemplate="{s}/{t}")>]
        member this.Get(s:string, t:string) : Stream =
            let html = sprintf @"
    <!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">
    <html><head></head><body>Called with '%s' and '%s'</body></html>" s t
            upcast new MemoryStream(System.Text.Encoding.UTF8.GetBytes(html))
    
    let Main() =
        let address = "http://localhost:64385/"
        let host = new WebServiceHost(typeof<MyContract>, new Uri(address))
        host.AddServiceEndpoint(typeof<MyContract>, new WebHttpBinding(), "") 
            |> ignore
        host.Open()
        printfn "Server running at %s" address
        printfn "Press a key to close server"
        System.Console.ReadKey() |> ignore
        host.Close()
    
    Main()
    // now go hit 
    // http://localhost:64385/foo/42
    // in your browser
    
        2
  •  4
  •   ademar Brian    11 年前

    https://github.com/SuaveIO/suave/blob/master/README.md

    Suave是一个简单的web开发工具# 服务器和一组组合器 操纵路线流和任务

        3
  •  1
  •   Mauricio Scheffer    15 年前

    看一看 frack (类似机架的接口),如果需要更好的语法, frank (建立在frack之上)。

    Kayak ,它写在C#上,但是你可以从F#轻松地使用它。

    推荐文章