-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram.fsx
47 lines (32 loc) · 1.12 KB
/
program.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#r "nuget: FSharp.Json"
module PokeApiModule =
open System.Net.Http
module private HttpClientModule =
let GetAsync (client:HttpClient) (endpoint:string) =
async {
let! response = client.GetAsync(endpoint) |> Async.AwaitTask
response.EnsureSuccessStatusCode() |> ignore
let! content = response.Content.ReadAsStringAsync() |> Async.AwaitTask
return content
}
let private _baseUrl = "https://pokeapi.co/api/v2/"
let GetPokemon dexNumber =
async {
use client = new HttpClient()
let endpoint = _baseUrl + "pokemon/" + dexNumber
let! pkmn = HttpClientModule.GetAsync client endpoint
return pkmn
}
type Pokemon = {
id : int
name : string
}
open System
open FSharp.Json
printf "Digite um número: " |> ignore
let num = Console.ReadLine()
let res = PokeApiModule.GetPokemon num
|> Async.RunSynchronously
|> Json.deserialize<Pokemon>
printf "%A : %A" res.id res.name
0