@@ -51,9 +51,9 @@ 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 " >
56
+ With Javascript, require the ` strapi ` function and create a client instance:
57
57
58
58
``` js
59
59
import { strapi } from ' @strapi/client' ;
@@ -62,9 +62,9 @@ const client = strapi({ baseURL: 'http://localhost:1337/api' });
62
62
```
63
63
</TabItem >
64
64
65
+ <TabItem value =" ts " label =" TypeScript " >
65
66
66
67
With Typescript, import the ` strapi ` function and create a client instance with your Strapi API base URL:
67
- <TabItem value =" ts " label =" TypeScript " >
68
68
69
69
``` typescript
70
70
import { strapi } from ' @strapi/client' ;
@@ -74,18 +74,21 @@ const client = strapi({ baseURL: 'http://localhost:1337/api' });
74
74
</TabItem >
75
75
76
76
77
- If you're using the Strapi Client in a browser environment, you can include it using a ` <script> ` tag.
78
77
<TabItem value =" browser " label =" Browser (UMD) " >
78
+ If you're using the Strapi Client in a browser environment, you can include it using a ` <script> ` tag.
79
+
79
80
``` js title="./src/api/[apiName]/routes/[routerName].ts (e.g './src/api/restaurant/routes/restaurant.ts')"
80
81
< script src= " https://cdn.jsdelivr.net/npm/@strapi/client" >< / script>
81
82
82
83
< script>
83
84
const client = strapi .strapi ({ baseURL: ' http://localhost:1337/api' });
84
85
< / script>
85
86
```
87
+
86
88
</TabItem >
87
89
The ` baseURL ` must include the protocol (` http ` or ` https ` ). An invalid URL will throw an error ` StrapiInitializationError ` .
88
90
91
+ </Tabs >
89
92
90
93
### Authentication
91
94
0 commit comments