1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { request } from "https://esm.town/v/yieldray/request";
export async function reqJSON<T = any>(
info: RequestInfo,
init?: RequestInit & {
query?: Record<string, string>;
},
): Promise<T> {
const res = await request(info, init);
if (res.ok)
if (res.headers.get("content-type")?.startsWith("application/json"))
return (await res.json()) as T;
else
throw new Error("Requested resource is not JSON :" + res);
else
throw new Error("Request failed:" + res);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023