mirror of
https://codeberg.org/reflect/reflect-client-js.git
synced 2025-09-13 23:43:41 +02:00
fix: set Content-Type headers for requests with payload (#7)
This commit is contained in:
parent
04e9c7ec84
commit
5d6b4a4675
2 changed files with 8 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "reflect-client",
|
"name": "reflect-client",
|
||||||
"version": "1.1.1",
|
"version": "1.1.2",
|
||||||
"main": "build/Reflect.js",
|
"main": "build/Reflect.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": {
|
"exports": {
|
||||||
|
|
|
@ -18,9 +18,14 @@ export default class Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set request header
|
||||||
|
private setHeader(name, value): void {
|
||||||
|
return this.headers[name] = value;
|
||||||
|
}
|
||||||
|
|
||||||
// Set API key to use for all requests
|
// Set API key to use for all requests
|
||||||
private setApiKey(key: string): void {
|
private setApiKey(key: string): void {
|
||||||
this.headers["Authorization"] = `Bearer ${key}`;
|
return this.setHeader("Authorization", `Bearer ${key}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get fully qualified URL to endpoint
|
// Get fully qualified URL to endpoint
|
||||||
|
@ -40,6 +45,7 @@ export default class Client {
|
||||||
|
|
||||||
// JSON stringify and append body to request if provided and is not a GET request
|
// JSON stringify and append body to request if provided and is not a GET request
|
||||||
if (payload && method !== Method.GET) {
|
if (payload && method !== Method.GET) {
|
||||||
|
this.setHeader("Content-Type", "application/json");
|
||||||
options["body"] = JSON.stringify(payload);
|
options["body"] = JSON.stringify(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue