Skip to content

Instantly share code, notes, and snippets.

@yelluw
Forked from awright18/Sample.fsproj
Created July 5, 2017 03:22
Show Gist options
  • Save yelluw/84400c15cc0813f358fce2ae97e0640a to your computer and use it in GitHub Desktop.
Save yelluw/84400c15cc0813f358fce2ae97e0640a to your computer and use it in GitHub Desktop.
F# http reqeust with HttpClient
// Learn more about F# at http://fsharp.org
open System
open System.Net.Http
[<EntryPoint>]
let main argv =
//Do whatever with XML stuff here
let parseXml x = x
// takes x parsed xml
// returns whatever you want
// ignore is just going to ignore whatever results you should do all youw work in the aync{ } and not return anything
let returnXml x = x |> ignore
let doXmlStuff = async {
let client = new HttpClient()
let! response = client.GetStringAsync("http://google.com")
|> Async.AwaitTask
let parsedStuff = parseXml response
returnXml parsedStuff
}
doXmlStuff |> Async.RunSynchronously
0 // return an integer exit code
<Project Sdk="FSharp.NET.Sdk;Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharp.Core" Version="4.1.*" />
<PackageReference Include="FSharp.NET.Sdk" Version="1.0.*" PrivateAssets="All" />
<!-- You need to add this for System.Net.Http to work. After adding this do a dotnet restore -->
<PackageReference Include="System.Net.Http" Version="4.3.*" />
</ItemGroup>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment