@@ -51,41 +51,48 @@ To use the Strapi Client in your project, install it as a dependency using your
51
51
52
52
To start interacting with your Strapi back end, initialize the Strapi Client and set the base API URL:
53
53
54
- With Javascript, require the ` strapi ` function and create a client instance:
55
54
<Tabs groupId =" js-ts " >
56
55
<TabItem value =" js " label =" JavaScript " >
57
56
57
+ With Javascript, require the ` strapi ` function and create a client instance:
58
+
58
59
``` js
59
60
import { strapi } from ' @strapi/client' ;
60
61
61
62
const client = strapi ({ baseURL: ' http://localhost:1337/api' });
62
63
```
64
+
63
65
</TabItem >
64
66
67
+ <TabItem value =" ts " label =" TypeScript " >
65
68
66
69
With Typescript, import the ` strapi ` function and create a client instance with your Strapi API base URL:
67
- <TabItem value =" ts " label =" TypeScript " >
68
70
69
71
``` typescript
70
72
import { strapi } from ' @strapi/client' ;
71
73
72
74
const client = strapi ({ baseURL: ' http://localhost:1337/api' });
73
75
```
76
+
74
77
</TabItem >
75
78
79
+ <TabItem value =" browser " label =" Browser (UMD) " >
76
80
77
81
If you're using the Strapi Client in a browser environment, you can include it using a ` <script> ` tag.
78
- < TabItem value = " browser " label = " Browser (UMD) " >
82
+
79
83
``` js title="./src/api/[apiName]/routes/[routerName].ts (e.g './src/api/restaurant/routes/restaurant.ts')"
80
84
< script src= " https://cdn.jsdelivr.net/npm/@strapi/client" >< / script>
81
85
82
86
< script>
83
87
const client = strapi .strapi ({ baseURL: ' http://localhost:1337/api' });
84
88
< / script>
85
89
```
90
+
86
91
</TabItem >
87
- The ` baseURL ` must include the protocol (` http ` or ` https ` ). An invalid URL will throw an error ` StrapiInitializationError ` .
88
92
93
+ </Tabs >
94
+
95
+ The ` baseURL ` must include the protocol (` http ` or ` https ` ). An invalid URL will throw an error ` StrapiInitializationError ` .
89
96
90
97
### Authentication
91
98
0 commit comments