-
Notifications
You must be signed in to change notification settings - Fork 2
/
api.ts
32 lines (27 loc) · 947 Bytes
/
api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Post } from "./types/post";
import { TeamMember } from "./types/team-member";
const baseAPI = `http://localhost:1337/api`;
export async function getTeam(): Promise<TeamMember[]> {
const response = await fetch(`${baseAPI}/members?populate=*`);
const data = await response.json();
return data.data;
}
export async function getTeamMember(username: string): Promise<TeamMember> {
const response = await fetch(
`${baseAPI}/members?filters[username]=${username}&[populate]=*`
);
const data = await response.json();
return data.data[0];
}
export async function getPostBySlug(slug: string): Promise<Post> {
const response = await fetch(
`${baseAPI}/posts?filters[slug]=${slug}&[populate]=*`
);
const data = await response.json();
return data.data[0];
}
export async function getPosts() {
const response = await fetch(`${baseAPI}/posts?populate=*`);
const data = await response.json();
return data.data;
}