@@ -46,18 +46,18 @@ The codemod supports the following Axios methods and converts them to their Fetc
4646### GET Request
4747
4848``` diff
49- const base = 'https://dummyjson.com/todos';
49+ const base = 'https://dummyjson.com/todos';
5050
5151- const all = await axios.get(base);
5252+ const all = await fetch(base).then(async (res) => Object.assign(res, { data: await res.json() })).catch(() => null);
53- console.log('\nGET /todos ->', all.status);
54- console.log(`Preview: ${all.data.todos.length} todos`);
53+ console.log('\nGET /todos ->', all.status);
54+ console.log(`Preview: ${all.data.todos.length} todos`);
5555```
5656
5757### POST Request
5858
5959``` diff
60- const base = 'https://dummyjson.com/todos';
60+ const base = 'https://dummyjson.com/todos';
6161
6262- const created = await axios.post(
6363- `${base}/add`, {
@@ -77,14 +77,14 @@ The codemod supports the following Axios methods and converts them to their Fetc
7777+ userId: 5,
7878+ }),
7979+ }).then(async (res) => Object.assign(res, { data: await res.json() }));
80- console.log('\nPOST /todos/add ->', created.status);
81- console.log('Preview:', created.data?.id ? `created id ${created.data.id}` : JSON.stringify(created.data).slice(0,200));
80+ console.log('\nPOST /todos/add ->', created.status);
81+ console.log('Preview:', created.data?.id ? `created id ${created.data.id}` : JSON.stringify(created.data).slice(0,200));
8282```
8383
8484### POST Form Request
8585
8686``` diff
87- const formEndpoint = '/submit';
87+ const formEndpoint = '/submit';
8888
8989- const created = await axios.postForm(formEndpoint, {
9090- title: 'Form Demo',
@@ -97,13 +97,13 @@ The codemod supports the following Axios methods and converts them to their Fetc
9797+ completed: false,
9898+ }),
9999+ }).then(async (res) => Object.assign(res, { data: await res.json() }));
100- console.log('Preview:', created.data);
100+ console.log('Preview:', created.data);
101101```
102102
103103### PUT Request
104104
105105``` diff
106- const base = 'https://dummyjson.com/todos';
106+ const base = 'https://dummyjson.com/todos';
107107
108108- const updatedPut = await axios.put(
109109- `${base}/1`,
@@ -115,26 +115,26 @@ The codemod supports the following Axios methods and converts them to their Fetc
115115+ headers: { 'Content-Type': 'application/json' },
116116+ body: JSON.stringify({ completed: false }),
117117+ }).then(async (res) => Object.assign(res, { data: await res.json() }));
118- console.log('\nPUT /todos/1 ->', updatedPut.status);
119- console.log('Preview:', updatedPut.data?.completed !== undefined ? `completed=${updatedPut.data.completed}` : JSON.stringify(updatedPut.data).slice(0,200));
118+ console.log('\nPUT /todos/1 ->', updatedPut.status);
119+ console.log('Preview:', updatedPut.data?.completed !== undefined ? `completed=${updatedPut.data.completed}` : JSON.stringify(updatedPut.data).slice(0,200));
120120```
121121
122122### DELETE Request
123123
124124``` diff
125- const base = 'https://dummyjson.com/todos';
125+ const base = 'https://dummyjson.com/todos';
126126
127127- const deleted = await axios.delete(`${base}/1`);
128128+ const deleted = await fetch(`${base}/1`, { method: 'DELETE' })
129129+ .then(async (res) => Object.assign(res, { data: await res.json() }));
130- console.log('\nDELETE /todos/1 ->', deleted.status);
131- console.log('Preview:', deleted.data ? JSON.stringify(deleted.data).slice(0,200) : typeof deleted.data);
130+ console.log('\nDELETE /todos/1 ->', deleted.status);
131+ console.log('Preview:', deleted.data ? JSON.stringify(deleted.data).slice(0,200) : typeof deleted.data);
132132```
133133
134134### ` request ` Axios Method
135135
136136``` diff
137- const base = 'https://dummyjson.com/todos';
137+ const base = 'https://dummyjson.com/todos';
138138
139139- const customRequest = await axios.request({
140140- url: `${base}/1`,
@@ -147,8 +147,8 @@ The codemod supports the following Axios methods and converts them to their Fetc
147147+ headers: { 'Content-Type': 'application/json' },
148148+ body: JSON.stringify({ completed: true }),
149149+ }).then(async (res) => Object.assign(res, { data: await res.json() }));
150- console.log('\nPATCH /todos/1 ->', customRequest.status);
151- console.log('Preview:', customRequest.data?.completed !== undefined ? `completed=${customRequest.data.completed}` : JSON.stringify(customRequest.data).slice(0,200));
150+ console.log('\nPATCH /todos/1 ->', customRequest.status);
151+ console.log('Preview:', customRequest.data?.completed !== undefined ? `completed=${customRequest.data.completed}` : JSON.stringify(customRequest.data).slice(0,200));
152152```
153153
154154## Unsupported APIs
0 commit comments