How do I use types declared in my host project and served over Ajax in the generated FunScript code?
For example I lets say I declare a type T and then create a REST endpoint serving data in that format. Now if I want to load the data and use it from FunScript its no longer type T.
Edited with solution based on Alfanso's answer:
Assuming type "MyType" is defined in the base F# project and data matching this type served on localhost:6543/myData
let start () =
async{
let url = "http://localhost:6543/myData"
let req = System.Net.WebRequest.Create(url)
let! data = req.AsyncGetJSON<MyType list>()
Globals.window.alert( (sprintf "%A" data) )
}
|> Async.StartImmediate
What I was missing was
- req.AsyncGetJSON
- Use Async.StartImmediate