-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-methods.ts
More file actions
52 lines (39 loc) · 1.13 KB
/
basic-methods.ts
File metadata and controls
52 lines (39 loc) · 1.13 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { createClient } from '@dfsync/client';
type Post = {
id: number;
title: string;
body: string;
userId: number;
};
const client = createClient({
baseUrl: 'https://jsonplaceholder.typicode.com',
timeout: 5000,
retry: {
attempts: 2,
},
});
async function main(): Promise<void> {
const posts = await client.get<Post[]>('/posts');
console.log('Posts:', posts.slice(0, 2));
const createdPost = await client.post<Post>('/posts', {
title: 'Hello from dfsync',
body: 'Created with @dfsync/client',
userId: 1,
});
console.log('Created post:', createdPost);
const patchedPost = await client.patch<Post>('/posts/1', {
title: 'Updated with PATCH',
});
console.log('Patched post:', patchedPost);
const deletedPost = await client.delete<undefined>('/posts/1');
console.log('Delete response (demo API does not persist changes):', deletedPost);
const singlePost = await client.request<Post>({
method: 'GET',
path: '/posts/1',
});
console.log('Single post via request():', singlePost);
}
main().catch((error) => {
console.error('Example failed:', error);
process.exit(1);
});