4141 - [ Custom Headers] ( #custom-headers )
42423 . [ API Reference] ( #-api-reference )
43434 . [ Resource Managers] ( #-resource-managers )
44- - [ ` .collection() ` ] ( #collectionresource )
45- - [ ` .single() ` ] ( #singleresource )
44+ - [ ` .collection() ` ] ( #collectionresource-options )
45+ - [ ` .single() ` ] ( #singleresource-options )
4646 - [ ` .files ` ] ( #files )
47475 . [ Debug] ( #-debug )
48486 . [ Demo Projects] ( #-demo-projects )
@@ -157,18 +157,23 @@ const articles = await client.collection('articles').find();
157157The Strapi client library instance provides key properties and utility methods for content and API interaction:
158158
159159- ** ` baseURL ` ** : base URL of your Strapi backend.
160- - ** ` fetch ` ** : perform generic requests to the Strapi Content API using fetch-like syntax.
161- - ** ` .collection(resource: string) ` ** : get a manager instance for handling collection-type resources.
162- - ** ` .single(resource: string) ` ** : get a manager instance for handling single-type resources.
160+ - ** ` fetch() ` ** : perform generic requests to the Strapi Content API using fetch-like syntax.
161+ - ** ` collection() ` ** : get a manager instance for handling collection-type resources.
162+ - ** ` single() ` ** : get a manager instance for handling single-type resources.
163+ - ** ` files ` ** : access the files manager instance for handling common files operations.
163164
164165## 📁 Resource Managers
165166
166- ### ` .collection(resource) `
167+ ### ` .collection(resource, [options] ) `
167168
168169The ` .collection() ` method provides a manager for working with collection-type resources,
169170which can have multiple entries.
170171
171- ** Note** : the ` resource ` corresponds to the plural name of your collection type, as defined in the Strapi model.
172+ #### Params
173+
174+ - ` resource ` : ` string ` - plural name of your collection type, as defined in the Strapi model
175+ - ` [options] ` : ` object ` - additional options to pass to the collection type manager
176+ - ` [path] ` : ` string ` - optional root path override for the manager's queries
172177
173178#### Available Methods:
174179
@@ -202,11 +207,21 @@ const updatedArticle = await articles.update('article-document-id', { title: 'Up
202207await articles .delete (' article-id' );
203208```
204209
205- ### ` .single(resource) `
210+ You can also customize the root path for requests by providing a value for the ` path ` option:
211+
212+ ``` typescript
213+ const articles = client .collection (' articles' , { path: ' /my-custom-path' });
214+ ```
215+
216+ ### ` .single(resource, [options]) `
206217
207218The ` .single() ` method provides a manager for working with single-type resources, which have only one entry.
208219
209- ** Note** : the ` resource ` corresponds to the singular name of your collection type, as defined in the Strapi model.
220+ #### Params
221+
222+ - ` resource ` : ` string ` - singular name of your single type, as defined in the Strapi model
223+ - ` [options] ` : ` object ` - additional options to pass to the single type manager
224+ - ` [path] ` : ` string ` - optional root path override for the manager's queries
210225
211226#### Available Methods:
212227
@@ -235,9 +250,15 @@ const updatedHomepage = await homepage.update(
235250await homepage .delete ();
236251```
237252
238- ### .files
253+ You can also customize the root path for requests by providing a value for the ` path ` option:
239254
240- The ` files ` property provides access to the Strapi Media Library through the Upload plugin. It allows you to retrieve files metadata without directly interacting with the REST API.
255+ ``` typescript
256+ const homepage = client .single (' homepage' , { path: ' /my-custom-path' });
257+ ```
258+
259+ ### ` .files `
260+
261+ The ` files ` property provides access to the Strapi Media Library through the Upload plugin. It allows you to retrieve files metadata without directly interacting with the REST API manually.
241262
242263#### Methods
243264
@@ -246,7 +267,9 @@ The `files` property provides access to the Strapi Media Library through the Upl
246267- ` update(fileId: number, fileInfo: FileUpdateData): Promise<FileResponse> ` - Updates metadata for an existing file
247268- ` delete(fileId: number): Promise<void> ` - Deletes a file by its ID
248269
249- #### Example: Finding Files
270+ #### Examples
271+
272+ ** Finding all files**
250273
251274``` typescript
252275// Initialize the client
@@ -269,7 +292,7 @@ const imageFiles = await client.files.find({
269292});
270293```
271294
272- #### Example: Finding a Single File
295+ ** Finding a Single File**
273296
274297``` typescript
275298// Initialize the client
@@ -286,7 +309,7 @@ console.log(file.url); // The file URL
286309console .log (file .mime ); // The file MIME type
287310```
288311
289- #### Example: Updating File Metadata
312+ ** Updating File Metadata**
290313
291314``` typescript
292315// Initialize the client
@@ -306,7 +329,7 @@ console.log(updatedFile.name); // Updated file name
306329console .log (updatedFile .alternativeText ); // Updated alt text
307330```
308331
309- #### Example: Deleting a File
332+ ** Deleting a File**
310333
311334``` typescript
312335// Initialize the client
@@ -387,6 +410,7 @@ This repository includes demo projects located in the `/demo` directory to help
387410- ** ` demo/node-typescript ` ** : a Node.js project using TypeScript.
388411- ** ` demo/node-javascript ` ** : a Node.js project using JavaScript.
389412- ** ` demo/next-server-components ` ** : a Next.js project using TypeScript and server components.
413+ - ** ` demo/react-vite ` ** : a React project using Vite and TypeScript
390414
391415### Using Demo Commands
392416
0 commit comments