Suave + Paket = ♥
Working fully self-contained getting-started example for Suave Web Server scripting
Note you don't need to have anything installed before starting with this script. Nothing but F# Interactive and this script.
This script fetches the Paket.exe component which is referenced later in the script. Initially the #r "paket.exe" reference is shown as unresolved. Once it has been downloaded by the user (by executing the first part of the script) the reference shows as resolved and can be used.
Paket is then used to fetch a set of F# packages, which are then used later in the script.
// Step 0. Boilerplate to get the paket.exe tool open System open System.IO Environment.CurrentDirectory <- __SOURCE_DIRECTORY__ if not (File.Exists "paket.exe") then let url = "https://github.com/fsprojects/Paket/releases/download/0.31.5/paket.exe" use wc = new Net.WebClient() let tmp = Path.GetTempFileName() wc.DownloadFile(url, tmp) File.Move(tmp,Path.GetFileName url);; // Step 1. Resolve and install the packages #r "paket.exe" Paket.Dependencies.Install """ frameworks: net46 source https://nuget.org/api/v2 nuget Suave """;; // Step 2. Use the packages #r "packages/Suave/lib/net40/Suave.dll" open Suave // always open suave startWebServer defaultConfig (Successful.OK "Hello World!")
namespace System
namespace System.IO
type Environment =
static member CommandLine : string
static member CurrentDirectory : string with get, set
static member CurrentManagedThreadId : int
static member Exit : exitCode:int -> unit
static member ExitCode : int with get, set
static member ExpandEnvironmentVariables : name:string -> string
static member FailFast : message:string -> unit + 1 overload
static member GetCommandLineArgs : unit -> string[]
static member GetEnvironmentVariable : variable:string -> string + 1 overload
static member GetEnvironmentVariables : unit -> IDictionary + 1 overload
...
nested type SpecialFolder
nested type SpecialFolderOption
Full name: System.Environment
static member CommandLine : string
static member CurrentDirectory : string with get, set
static member CurrentManagedThreadId : int
static member Exit : exitCode:int -> unit
static member ExitCode : int with get, set
static member ExpandEnvironmentVariables : name:string -> string
static member FailFast : message:string -> unit + 1 overload
static member GetCommandLineArgs : unit -> string[]
static member GetEnvironmentVariable : variable:string -> string + 1 overload
static member GetEnvironmentVariables : unit -> IDictionary + 1 overload
...
nested type SpecialFolder
nested type SpecialFolderOption
Full name: System.Environment
property Environment.CurrentDirectory: string
val not : value:bool -> bool
Full name: Microsoft.FSharp.Core.Operators.not
Full name: Microsoft.FSharp.Core.Operators.not
type File =
static member AppendAllLines : path:string * contents:IEnumerable<string> -> unit + 1 overload
static member AppendAllText : path:string * contents:string -> unit + 1 overload
static member AppendText : path:string -> StreamWriter
static member Copy : sourceFileName:string * destFileName:string -> unit + 1 overload
static member Create : path:string -> FileStream + 3 overloads
static member CreateText : path:string -> StreamWriter
static member Decrypt : path:string -> unit
static member Delete : path:string -> unit
static member Encrypt : path:string -> unit
static member Exists : path:string -> bool
...
Full name: System.IO.File
static member AppendAllLines : path:string * contents:IEnumerable<string> -> unit + 1 overload
static member AppendAllText : path:string * contents:string -> unit + 1 overload
static member AppendText : path:string -> StreamWriter
static member Copy : sourceFileName:string * destFileName:string -> unit + 1 overload
static member Create : path:string -> FileStream + 3 overloads
static member CreateText : path:string -> StreamWriter
static member Decrypt : path:string -> unit
static member Delete : path:string -> unit
static member Encrypt : path:string -> unit
static member Exists : path:string -> bool
...
Full name: System.IO.File
File.Exists(path: string) : bool
val url : string
val wc : Net.WebClient
namespace System.Net
Multiple items
type WebClient =
inherit Component
new : unit -> WebClient
member AllowReadStreamBuffering : bool with get, set
member AllowWriteStreamBuffering : bool with get, set
member BaseAddress : string with get, set
member CachePolicy : RequestCachePolicy with get, set
member CancelAsync : unit -> unit
member Credentials : ICredentials with get, set
member DownloadData : address:string -> byte[] + 1 overload
member DownloadDataAsync : address:Uri -> unit + 1 overload
member DownloadDataTaskAsync : address:string -> Task<byte[]> + 1 overload
...
Full name: System.Net.WebClient
--------------------
Net.WebClient() : unit
type WebClient =
inherit Component
new : unit -> WebClient
member AllowReadStreamBuffering : bool with get, set
member AllowWriteStreamBuffering : bool with get, set
member BaseAddress : string with get, set
member CachePolicy : RequestCachePolicy with get, set
member CancelAsync : unit -> unit
member Credentials : ICredentials with get, set
member DownloadData : address:string -> byte[] + 1 overload
member DownloadDataAsync : address:Uri -> unit + 1 overload
member DownloadDataTaskAsync : address:string -> Task<byte[]> + 1 overload
...
Full name: System.Net.WebClient
--------------------
Net.WebClient() : unit
val tmp : string
type Path =
static val InvalidPathChars : char[]
static val AltDirectorySeparatorChar : char
static val DirectorySeparatorChar : char
static val PathSeparator : char
static val VolumeSeparatorChar : char
static member ChangeExtension : path:string * extension:string -> string
static member Combine : [<ParamArray>] paths:string[] -> string + 3 overloads
static member GetDirectoryName : path:string -> string
static member GetExtension : path:string -> string
static member GetFileName : path:string -> string
...
Full name: System.IO.Path
static val InvalidPathChars : char[]
static val AltDirectorySeparatorChar : char
static val DirectorySeparatorChar : char
static val PathSeparator : char
static val VolumeSeparatorChar : char
static member ChangeExtension : path:string * extension:string -> string
static member Combine : [<ParamArray>] paths:string[] -> string + 3 overloads
static member GetDirectoryName : path:string -> string
static member GetExtension : path:string -> string
static member GetFileName : path:string -> string
...
Full name: System.IO.Path
Path.GetTempFileName() : string
Net.WebClient.DownloadFile(address: Uri, fileName: string) : unit
Net.WebClient.DownloadFile(address: string, fileName: string) : unit
Net.WebClient.DownloadFile(address: string, fileName: string) : unit
File.Move(sourceFileName: string, destFileName: string) : unit
Path.GetFileName(path: string) : string
namespace Suave
val startWebServer : config:SuaveConfig -> webpart:WebPart -> unit
Full name: Suave.Web.startWebServer
Full name: Suave.Web.startWebServer
val defaultConfig : SuaveConfig
Full name: Suave.Web.defaultConfig
Full name: Suave.Web.defaultConfig
module Successful
from Suave
from Suave
val OK : body:string -> WebPart
Full name: Suave.Successful.OK
Full name: Suave.Successful.OK