#Help with the fetch module

1 messages · Page 1 of 1 (latest)

errant badge
#

Hello ! My question seem stupid... I am currently using Gleam and testing some cool features about it and i have a problem using the gleam_fetch module, i wan't to have a function that just returns the string of a JSON i am fetching : ```
pub fn read_json()->String{
let assert Ok(req) = request.to("http://127.0.0.1:8000/data/assets.json")

// Send the HTTP request to the server
use resp <- promise.try_await(fetch.send(req))
use resp <- promise.try_await(fetch.read_text_body(resp))

resp.body
}
But i have a little probem ^^', i can't just return the body like that cause it actually expects afn(Response(String)) -> Promise(Result(a, FetchError))``` type :'(, after some researches, i really don't find a good solution, can somebody help me with that please ?

solemn summit
#

not sure if you are familiar with promises in javascript, but there is no way to "extract" the value from a promise, i.e. remove the Promise<Whatever> wrapper