Skip to content

Instantly share code, notes, and snippets.

@edgarfgp
Created March 8, 2020 10:56
Show Gist options
  • Save edgarfgp/33830d5a372f568b12958f6c9a0bc767 to your computer and use it in GitHub Desktop.
Save edgarfgp/33830d5a372f568b12958f6c9a0bc767 to your computer and use it in GitHub Desktop.
namespace DynamicUI
open DynamicUI.Models
open FSharp.Data
open FSharp.Json
module NetworkService =
let getMusicDataSearch (searchText: string option) =
async {
let term =
match searchText with
| Some value -> value
| _ -> ""
let urlString = sprintf "https://itunes.apple.com/search?term=%A" term
let! musicEntries = Async.Catch(Http.AsyncRequestString(urlString))
let searchResult =
match musicEntries with
| Choice1Of2 musicList ->
let musicList = Json.deserialize<MusicList> musicList
Ok musicList.results
| Choice2Of2 error -> Error error
return searchResult
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment