1- import z from 'zod'
1+ // import z from 'zod'
22// import { fakeFetch } from './utils'
33
4+ const API = 'http://localhost:3333'
5+ // const API = 'http://swapi.dev/api'
6+
47/****************************************
58 Part 1: Request
69*****************************************/
710
8- // function getPerson(id: number) {
9- // fetch(`https://swapi.dev/api /people/${id}`).then(() => {
10- // console.log('Promise is resolved')
11- // })
12- // }
11+ function getPerson ( id : number ) {
12+ fetch ( `${ API } /people/${ id } ` ) . then ( ( ) => {
13+ console . log ( 'Promise is resolved' )
14+ } )
15+ }
1316
14- // getPerson(1)
17+ getPerson ( 1 )
1518
1619/****************************************
1720 Part 2: Response
@@ -21,7 +24,7 @@ import z from 'zod'
2124// https://developer.mozilla.org/en-US/docs/Web/API/fetch#return_value
2225
2326// function getPerson(id: number) {
24- // fetch(`https://swapi.dev/api /people/${id}`).then((res) => {
27+ // fetch(`${API} /people/${id}`).then((res) => {
2528// console.log('What is in the response', res)
2629// })
2730// }
@@ -42,26 +45,26 @@ import z from 'zod'
4245 Part 4: Typesafe Network Response
4346*****************************************/
4447
45- // const personSchema = z.object({
46- // name: z.string(),
47- // height: z.string().transform((val) => Number(val)),
48- // })
48+ // // const personSchema = z.object({
49+ // // name: z.string(),
50+ // // height: z.string().transform((val) => Number(val)),
51+ // / / })
4952
50- // type Person = z.infer<typeof personSchema>
53+ // // type Person = z.infer<typeof personSchema>
5154
52- type Person = {
53- name : string
54- height : number
55- }
55+ // type Person = {
56+ // name: string
57+ // height: number
58+ // }
5659
57- function getPerson ( id : number ) {
58- return fetch ( `https://swapi.dev/api /people/${ id } ` )
59- . then ( ( res ) => res . json ( ) )
60- . then ( ( data ) => {
61- return data as Person
62- } )
63- }
60+ // function getPerson(id: number) {
61+ // return fetch(`${API} /people/${id}`)
62+ // .then((res) => res.json())
63+ // .then((data) => {
64+ // return data as Person
65+ // })
66+ // }
6467
65- getPerson ( 1 ) . then ( ( person ) => {
66- console . log ( person )
67- } )
68+ // getPerson(1).then((person) => {
69+ // console.log(person)
70+ // })
0 commit comments