Merge branch 'dev' into frontend
This commit is contained in:
commit
974d86c2d9
4 changed files with 50 additions and 0 deletions
32
frontend/src/API/API.ts
Normal file
32
frontend/src/API/API.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
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>);
|
||||
},
|
||||
};
|
3
frontend/src/API/README.md
Normal file
3
frontend/src/API/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# API
|
||||
|
||||
This file contains the high-level API interface and implementation.
|
4
frontend/src/Types/README.md
Normal file
4
frontend/src/Types/README.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
# Types
|
||||
|
||||
This directory contains TypeScript type definitions for the frontend.
|
||||
This is primarily used by, but not limited to, the API responses and requests.
|
11
frontend/src/Types/Users.ts
Normal file
11
frontend/src/Types/Users.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
// This is how the API responds
|
||||
export interface User {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
// Used to create a new user
|
||||
export interface NewUser {
|
||||
name: string;
|
||||
password: string;
|
||||
}
|
Loading…
Reference in a new issue