33 lines
895 B
TypeScript
33 lines
895 B
TypeScript
![]() |
import { NewUser, User } from "../Types/Users";
|
||
|
|
||
|
// Defines all the methods that an instance of the API must implement
|
||
|
interface API {
|
||
|
/** Register a new user */
|
||
|
registerUser(user: NewUser): Promise<User>;
|
||
|
/** Remove a user */
|
||
|
removeUser(username: string): Promise<User>;
|
||
|
}
|
||
|
|
||
|
// Export an instance of the API
|
||
|
export const api: API = {
|
||
|
async registerUser(user: NewUser): Promise<User> {
|
||
|
return fetch("/api/register", {
|
||
|
method: "POST",
|
||
|
headers: {
|
||
|
"Content-Type": "application/json",
|
||
|
},
|
||
|
body: JSON.stringify(user),
|
||
|
}).then((res) => res.json() as Promise<User>);
|
||
|
},
|
||
|
|
||
|
async removeUser(username: string): Promise<User> {
|
||
|
return fetch("/api/userdelete", {
|
||
|
method: "POST",
|
||
|
headers: {
|
||
|
"Content-Type": "application/json",
|
||
|
},
|
||
|
body: JSON.stringify(username),
|
||
|
}).then((res) => res.json() as Promise<User>);
|
||
|
},
|
||
|
};
|