Template
1
0
Files
boilerplate/adapters/http.ts
2025-04-18 21:27:08 +00:00

17 lines
534 B
TypeScript

import { RequestInput } from "../libraries/relay.ts";
import { RelayAdapter } from "../mod.ts";
export const adapter: RelayAdapter = {
async fetch({ method, url, search, body }: RequestInput) {
const res = await fetch(`${url}${search}`, { method, headers: { "content-type": "application/json" }, body });
const data = await res.text();
if (res.status >= 400) {
throw new Error(data);
}
if (res.headers.get("content-type")?.includes("json")) {
return JSON.parse(data);
}
return data;
},
};