-
-
Save yelluw/84400c15cc0813f358fce2ae97e0640a to your computer and use it in GitHub Desktop.
F# http reqeust with HttpClient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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