monorepo icon indicating copy to clipboard operation
monorepo copied to clipboard

2. Onboarding Fetch Examples

Open 7alip opened this issue 1 year ago • 0 comments

Tasks

  • [x] Create a new branch from dev with your username onboarding/fetch-<username>
  • [x] Write your code directly in the examples files
    • packages/ui/src/examples/E1_FetchWithAxios.tsx
    • packages/ui/src/examples/E2_FetchWithStrapiRequest.tsx
    • packages/ui/src/examples/E3_FetchWithFilters.tsx
  • [x] See results in Storybook (yarn storybook)

Example

https://docs.strapi.io/dev-docs/api/rest/filters-locale-publication#filtering

const qs = require('qs');
const query = qs.stringify({
  filters: {
    username: {
      $eq: 'John',
    },
  },
}, {
  encodeValuesOnly: true, // prettify URL
});

await fetch(`http://localhost:1337/api/users?${query}`);
// http://localhost:1337/api/users?filters[username][$eq]=John

7alip avatar Jul 06 '23 22:07 7alip