feat: initial commit
This commit is contained in:
16
adapters/http.ts
Normal file
16
adapters/http.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { RequestInput } from "../libraries/relay.ts";
|
||||
import { RelayAdapter } from "../mod.ts";
|
||||
|
||||
export const http: RelayAdapter = {
|
||||
async fetch({ method, url, search, body }: RequestInput) {
|
||||
const res = await fetch(`${url}${search}`, { method, 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;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user