Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Commit 32fcea8

Browse files
authored
refactor(routes): pluralized according to Strapi
Adapt to new pluralize routes
2 parents b32d5f3 + 2034be4 commit 32fcea8

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ await strapi.authenticateProvider('facebook');
4646
```
4747
You can now fetch private APIs
4848
```js
49-
const posts = await strapi.getEntries('post');
49+
const posts = await strapi.getEntries('posts');
5050
```
5151

5252
### Files management
@@ -83,11 +83,11 @@ const files = await strapi.upload(form, {
8383
### `authenticateProvider(provider, params)`
8484
### `setToken(token, comesFromStorage)`
8585
### `clearToken(token)`
86-
### `getEntries(contentType, params)`
87-
### `getEntry(contentType, id)`
88-
### `createEntry(contentType, data)`
89-
### `updateEntry(contentType, id, data)`
90-
### `deleteEntry(contentType, id)`
86+
### `getEntries(contentTypePluralized, params)`
87+
### `getEntry(contentTypePluralized, id)`
88+
### `createEntry(contentTypePluralized, data)`
89+
### `updateEntry(contentTypePluralized, id, data)`
90+
### `deleteEntry(contentTypePluralized, id)`
9191
### `searchFiles(query)`
9292
### `getFiles(params)`
9393
### `getFile(id)`

src/lib/sdk.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -225,64 +225,67 @@ export default class Strapi {
225225

226226
/**
227227
* List entries
228-
* @param contentType
228+
* @param contentTypePluralized
229229
* @param params Filter and order queries.
230230
*/
231231
public getEntries(
232-
contentType: string,
232+
contentTypePluralized: string,
233233
params?: AxiosRequestConfig['params']
234234
): Promise<object[]> {
235-
return this.request('get', `/${contentType}`, {
235+
return this.request('get', `/${contentTypePluralized}`, {
236236
params
237237
});
238238
}
239239

240240
/**
241241
* Get a specific entry
242-
* @param contentType Type of entry
242+
* @param contentTypePluralized Type of entry pluralized
243243
* @param id ID of entry
244244
*/
245-
public getEntry(contentType: string, id: string): Promise<object> {
246-
return this.request('get', `/${contentType}/${id}`);
245+
public getEntry(contentTypePluralized: string, id: string): Promise<object> {
246+
return this.request('get', `/${contentTypePluralized}/${id}`);
247247
}
248248

249249
/**
250250
* Create data
251-
* @param contentType Type of entry
251+
* @param contentTypePluralized Type of entry pluralized
252252
* @param data New entry
253253
*/
254254
public createEntry(
255-
contentType: string,
255+
contentTypePluralized: string,
256256
data: AxiosRequestConfig['data']
257257
): Promise<object> {
258-
return this.request('post', `/${contentType}`, {
258+
return this.request('post', `/${contentTypePluralized}`, {
259259
data
260260
});
261261
}
262262

263263
/**
264264
* Update data
265-
* @param contentType Type of entry
265+
* @param contentTypePluralized Type of entry pluralized
266266
* @param id ID of entry
267267
* @param data
268268
*/
269269
public updateEntry(
270-
contentType: string,
270+
contentTypePluralized: string,
271271
id: string,
272272
data: AxiosRequestConfig['data']
273273
): Promise<object> {
274-
return this.request('put', `/${contentType}/${id}`, {
274+
return this.request('put', `/${contentTypePluralized}/${id}`, {
275275
data
276276
});
277277
}
278278

279279
/**
280280
* Delete an entry
281-
* @param contentType Type of entry
281+
* @param contentTypePluralized Type of entry pluralized
282282
* @param id ID of entry
283283
*/
284-
public deleteEntry(contentType: string, id: string): Promise<object> {
285-
return this.request('delete', `/${contentType}/${id}`);
284+
public deleteEntry(
285+
contentTypePluralized: string,
286+
id: string
287+
): Promise<object> {
288+
return this.request('delete', `/${contentTypePluralized}/${id}`);
286289
}
287290

288291
/**

0 commit comments

Comments
 (0)