ky
ky copied to clipboard
Content-Type detection
I'm manually doing content detection:
const response = await ky
.post(tokenURL, {
body: formData,
})
switch (response.headers.get("Content-Type")) {
case "application/json": {
const parsed: AuthData = await response.json();
// etc
}
case "application/x-www-form-urlencoded": {
const parsed = await response.formData();
// etc
}
default: {
throw new TypeError(
"Error getting OAuth2 token: unexpected response format",
);
}
}
Would it make sense to have an .auto()
parser that deals with the content type automatically? JSON, FormData, Blob, etc. I think that's what Axios does for example (but it returns unknown
as a type)