Skip to content

Instantly share code, notes, and snippets.

@dsyme
Last active November 29, 2016 06:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsyme/9c95a66a18b2c625b057 to your computer and use it in GitHub Desktop.
Save dsyme/9c95a66a18b2c625b057 to your computer and use it in GitHub Desktop.
S
//==========================================
// Hypothetical fully self-contained getting-started example for Suave Web Server scripting
//
// 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.
//------------------------------------------
// Step 0. Boilerplate to get the package bootstrap, See http://fslang.uservoice.com/forums/245727-f-language/suggestions/7039406-add-a-scripting-module-to-fsharp-core-dll-inclu
open Scripting
System.Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
if not (fileExists "paket.exe") then
httpGet "https://github.com/fsprojects/Paket/releases/download/0.26.2/paket.exe" "paket.exe" ;;
//------------------------------------------
// Step 1. Resolve and install the packages
#r "paket.exe"
Paket.Scripting.Install """
source https://nuget.org/api/v2
nuget Suave 0.16.0
nuget FSharp.Data
nuget FSharp.Charting
""" ;;
//------------------------------------------
// Step 2. Use the packages
#r "packages/Suave/lib/Suave.dll"
#r "packages/FSharp.Data/lib/net40/FSharp.Data.dll"
#r "packages/FSharp.Charting/lib/net40/FSharp.Charting.dll"
let ctxt = FSharp.Data.WorldBankData.GetDataContext()
let data = ctxt.Countries.Algeria.Indicators.``GDP (current US$)``
open Suave // always open suave
open Suave.Http.Successful // for OK-result
open Suave.Web // for config
web_server default_config (OK (sprintf "Hello World! In 2010 Algeria earned %f " data.[2010]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment