-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove plugins. Utilize rest api instead of fileipc.
- Loading branch information
Showing
30 changed files
with
466 additions
and
2,451 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
export class RestClient { | ||
private baseUrl: string // Declare the types | ||
private token: string | ||
|
||
constructor(baseUrl: string, token: string) { | ||
this.baseUrl = baseUrl | ||
this.token = token | ||
} | ||
|
||
get(path: string) { | ||
return this.fetch(path, { method: "GET" }) | ||
} | ||
|
||
// deno-lint-ignore no-explicit-any | ||
post(path: string, data: any) { // 'any' for flexibility on the data type | ||
return this.fetch(path, { | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: data ? JSON.stringify(data) : undefined, | ||
}) | ||
} | ||
|
||
/** | ||
* @throws | ||
*/ | ||
// deno-lint-ignore no-explicit-any | ||
async fetch(path: string, options: RequestInit): Promise<any> { | ||
// Use RequestInit for options and allow 'any' for the response for now | ||
const headers = { | ||
"Authorization": "Bearer " + this.token, | ||
...options.headers, | ||
} | ||
const response = await fetch(this.baseUrl + path, { | ||
...options, | ||
headers, | ||
}) | ||
|
||
if (!response.ok) { | ||
const errorText = `Request failed: ${response.statusText}` | ||
throw new Error(errorText) | ||
} | ||
|
||
return response | ||
} | ||
} |
Oops, something went wrong.