| 1 | module js |
| 2 | |
| 3 | import js.promise |
| 4 | |
| 5 | pub fn JS.fetch(input JS.String, init JS.Object) JS.Promise |
| 6 | |
| 7 | pub interface JS.Body { |
| 8 | body JS.Uint8Array |
| 9 | bodyUse JS.Boolean |
| 10 | blob() JS.Promise |
| 11 | json() JS.Promise |
| 12 | text() JS.Promise |
| 13 | } |
| 14 | |
| 15 | pub interface JS.Response { |
| 16 | JS.Body |
| 17 | ok JS.Boolean |
| 18 | redirected JS.Boolean |
| 19 | status JS.Number |
| 20 | statusText JS.String |
| 21 | url JS.String |
| 22 | clone() JS.Response |
| 23 | } |
| 24 | |
| 25 | pub fn fetch(input string, init map[string]JS.Any) promise.Promise[JS.Response, JS.String] { |
| 26 | p_init := JS.Any(unsafe { nil }) |
| 27 | p := promise.Promise[JS.Response, String]{p_init} |
| 28 | |
| 29 | #let obj = {}; for (let [key,val] of init.map) { obj[key] = val; } |
| 30 | #p.promise = fetch(input.str,obj); |
| 31 | |
| 32 | return p |
| 33 | } |
| 34 | |