-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add examples.fsproj with Oryx.ThothJsonNet example (#58)
* Add examples.fsproj with Oryx.ThothJsonNet example * Move Thoth.Json.Net to new Examples group in paket.dependencies
- Loading branch information
Showing
6 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
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
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 |
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
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> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
group Examples | ||
Thoth.Json.Net |
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
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
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