Skip to content

Commit

Permalink
Add examples.fsproj with Oryx.ThothJsonNet example (#58)
Browse files Browse the repository at this point in the history
* Add examples.fsproj with Oryx.ThothJsonNet example

* Move Thoth.Json.Net to new Examples group in paket.dependencies
  • Loading branch information
da9l authored Jul 31, 2020
1 parent 7527c42 commit 875b521
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 1 deletion.
56 changes: 56 additions & 0 deletions examples/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
open System.Net.Http
open System.Text.Json

open FSharp.Control.Tasks.V2.ContextInsensitive

open Oryx
open Oryx.ThothJsonNet.ResponseReader
open Thoth.Json.Net

type WikiSearchHit =
| SearchTerm of string
| SearchHits of string list

type WikiSearchHits = WikiSearchHits of WikiSearchHit list

let wikiDataItemDecoder : Decoder<WikiSearchHit> =
Decode.oneOf [
Decode.string |> Decode.map SearchTerm
Decode.list Decode.string |> Decode.map SearchHits
]

let wikiDataItemsDecoders : Decoder<WikiSearchHits> =
Decode.list wikiDataItemDecoder
|> Decode.map WikiSearchHits

[<Literal>]
let Url = "https://en.wikipedia.org/w/api.php"

let options = JsonSerializerOptions()

let query term = [
struct ("action", "opensearch")
struct ("search", term)
]

let request term =
GET
>=> withUrl Url
>=> withQuery (query term)
>=> fetch
>=> json wikiDataItemsDecoders

let asyncMain argv = task {
use client = new HttpClient ()
let ctx =
Context.defaultContext
|> Context.withHttpClient client

let! result = request "F#" |> runAsync ctx
printfn "Result: %A" result
}

[<EntryPoint>]
let main argv =
asyncMain().GetAwaiter().GetResult()
0 // return an integer exit code
15 changes: 15 additions & 0 deletions examples/examples.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\src\Oryx.fsproj" />
<ProjectReference Include="..\extensions\Oryx.ThothJsonNet\Oryx.ThothJsonNet.fsproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<Import Project="..\.paket\Paket.Restore.targets" />
</Project>
2 changes: 2 additions & 0 deletions examples/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
group Examples
Thoth.Json.Net
14 changes: 14 additions & 0 deletions oryx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Oryx.NewtonsoftJson", "exte
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Oryx.ThothJsonNet", "extensions\Oryx.ThothJsonNet\Oryx.ThothJsonNet.fsproj", "{535AE660-B32C-4833-8C7B-A8DAEA8799E1}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "examples", "examples\examples.fsproj", "{755A4763-1976-41A1-91A2-FFB772343479}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -116,6 +118,18 @@ Global
{535AE660-B32C-4833-8C7B-A8DAEA8799E1}.Release|x64.Build.0 = Release|Any CPU
{535AE660-B32C-4833-8C7B-A8DAEA8799E1}.Release|x86.ActiveCfg = Release|Any CPU
{535AE660-B32C-4833-8C7B-A8DAEA8799E1}.Release|x86.Build.0 = Release|Any CPU
{755A4763-1976-41A1-91A2-FFB772343479}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{755A4763-1976-41A1-91A2-FFB772343479}.Debug|Any CPU.Build.0 = Debug|Any CPU
{755A4763-1976-41A1-91A2-FFB772343479}.Debug|x64.ActiveCfg = Debug|Any CPU
{755A4763-1976-41A1-91A2-FFB772343479}.Debug|x64.Build.0 = Debug|Any CPU
{755A4763-1976-41A1-91A2-FFB772343479}.Debug|x86.ActiveCfg = Debug|Any CPU
{755A4763-1976-41A1-91A2-FFB772343479}.Debug|x86.Build.0 = Debug|Any CPU
{755A4763-1976-41A1-91A2-FFB772343479}.Release|Any CPU.ActiveCfg = Release|Any CPU
{755A4763-1976-41A1-91A2-FFB772343479}.Release|Any CPU.Build.0 = Release|Any CPU
{755A4763-1976-41A1-91A2-FFB772343479}.Release|x64.ActiveCfg = Release|Any CPU
{755A4763-1976-41A1-91A2-FFB772343479}.Release|x64.Build.0 = Release|Any CPU
{755A4763-1976-41A1-91A2-FFB772343479}.Release|x86.ActiveCfg = Release|Any CPU
{755A4763-1976-41A1-91A2-FFB772343479}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{EDBBC8E4-1CAF-41BA-B945-6AC59717D720} = {C9E10FD9-70B4-421A-BDB1-421F5901CB7C}
Expand Down
7 changes: 7 additions & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ group Main
nuget FSharp.Core ~> 4.7
nuget Taskbuilder.fs ~> 2.1


group Json
source https://www.nuget.org/api/v2
storage: none
Expand Down Expand Up @@ -71,3 +72,9 @@ group Benchmark
nuget Thoth.Json.Net
nuget Utf8Json
nuget Ply

group Examples
source https://www.nuget.org/api/v2
storage: none

nuget Thoth.Json.Net
15 changes: 14 additions & 1 deletion paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ STORAGE: NONE
RESTRICTION: == netstandard2.0
NUGET
remote: https://www.nuget.org/api/v2
FSharp.Core (4.7)
FSharp.Core (4.7.2)
Microsoft.Bcl.AsyncInterfaces (1.1)
System.Threading.Tasks.Extensions (>= 4.5.2)
Microsoft.Extensions.Configuration (3.1.1)
Expand Down Expand Up @@ -695,6 +695,19 @@ NUGET
System.Threading.Tasks.Extensions (>= 4.4) - restriction: || (&& (>= net45) (< netstandard2.0)) (&& (< net45) (>= netstandard2.0)) (>= net47)
System.ValueTuple (>= 4.4) - restriction: || (&& (>= net45) (< netstandard2.0)) (&& (< net45) (>= netstandard2.0)) (>= net47)

GROUP Examples
STORAGE: NONE
NUGET
remote: https://www.nuget.org/api/v2
Fable.Core (3.1.5) - restriction: && (< net46) (>= netstandard2.0)
FSharp.Core (>= 4.7) - restriction: >= netstandard2.0
FSharp.Core (4.7.2) - restriction: || (>= net46) (>= netstandard2.0)
Newtonsoft.Json (12.0.3) - restriction: || (>= net46) (>= netstandard2.0)
Thoth.Json.Net (4.1)
Fable.Core (>= 3.0 < 4.0) - restriction: && (< net46) (>= netstandard2.0)
FSharp.Core (>= 4.6.2) - restriction: || (>= net46) (>= netstandard2.0)
Newtonsoft.Json (>= 11.0.2) - restriction: || (>= net46) (>= netstandard2.0)

GROUP Google
STORAGE: NONE
RESTRICTION: == netstandard2.0
Expand Down

0 comments on commit 875b521

Please sign in to comment.