### Install Sendgrid Email Provider (Yarn) Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-code.txt Example command to install the Sendgrid email provider using Yarn. ```bash yarn add @strapi/provider-email-sendgrid ``` -------------------------------- ### Install Sendgrid Email Provider (NPM) Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-code.txt Example command to install the Sendgrid email provider using NPM. ```bash npm install @strapi/provider-email-sendgrid --save ``` -------------------------------- ### Minimal vs. Full Configuration Examples Source: https://github.com/strapi/documentation/blob/main/claude-plugins/inki/references/authoring/AGENTS.cms.configurations.md Employ `` to differentiate between minimal and full configuration examples, aiding readers in understanding basic setup versus comprehensive options. ```javascript // Minimal configuration code // Full configuration code ``` -------------------------------- ### Install Dependencies and Start Development Server Source: https://github.com/strapi/documentation/blob/main/AGENTS.md Installs project dependencies using Yarn and starts the Docusaurus development server. This command is essential for local development and previewing changes. ```bash yarn && yarn dev ``` -------------------------------- ### Example GET /path Source: https://github.com/strapi/documentation/blob/main/claude-plugins/inki/references/templates/api-template.md Example cURL command to call the GET /path endpoint. Ensure to include the Authorization header. ```bash curl -H "Authorization: Bearer …" https://example.com/path ``` -------------------------------- ### Install Strapi Project with NPM Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/quick-start.md Use this command to create a new Strapi project locally using NPM. It will guide you through the setup process, including Strapi Cloud account creation. ```bash npx create-strapi@latest my-strapi-project ``` -------------------------------- ### Basic example custom configuration for plugins Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/configurations/plugins.md This example demonstrates how to enable a plugin without specific configuration, enable a custom local plugin with its resolve path and configuration, and explicitly disable an installed plugin. ```js module.exports = ({ env }) => ({ // enable a plugin that doesn't require any configuration i18n: true, // enable a custom plugin myplugin: { // my-plugin is going to be the internal name used for this plugin enabled: true, resolve: './src/plugins/my-local-plugin', config: { // user plugin config goes here }, }, // disable a plugin 'my-other-plugin': { enabled: false, // plugin installed but disabled }, }); ``` ```ts export default ({ env }) => ({ // enable a plugin that doesn't require any configuration i18n: true, // enable a custom plugin myplugin: { // my-plugin is going to be the internal name used for this plugin enabled: true, resolve: './src/plugins/my-local-plugin', config: { // user plugin config goes here }, }, // disable a plugin 'my-other-plugin': { enabled: false, // plugin installed but disabled }, }); ``` -------------------------------- ### Local Plugin Configuration with SDK Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/plugins-development/create-a-plugin.md Example configuration for a local plugin using `@strapi/sdk-plugin` in `/config/plugins.js|ts`. ```js myplugin: { enabled: true, resolve: `./src/plugins/local-plugin`, }, ``` -------------------------------- ### Generic Core Router Implementation Example Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-full.txt This example demonstrates a generic implementation for a core router, specifically allowing only a GET request on the `/restaurants` path from the `find` controller without authentication. ```javascript const { createCoreRouter } = require('@strapi/strapi/lib/core-api/router'); module.exports = createCoreRouter('api::restaurant.restaurant', { only: ['find'], config: { find: { auth: false, }, }, }); ``` -------------------------------- ### Hello World Route and Controller Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/backend-customization/controllers.md Example demonstrating how to define a simple GET route and its corresponding controller action to return 'Hello World!'. ```js module.exports = { routes: [ { method: 'GET', path: '/hello', handler: 'api::hello.hello.index', } ] } ``` ```js module.exports = { async index(ctx, next) { // called by GET /hello ctx.body = 'Hello World!'; // we could also send a JSON }, }; ``` -------------------------------- ### ./.env Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/installation/docker.md Example .env file with placeholder values for server, database, secrets, and environment settings. These values should be replaced before starting containers. ```bash # Server HOST=0.0.0.0 PORT=1337 # Database # Use 'mysql' for MySQL or MariaDB, and change DATABASE_PORT to 3306 DATABASE_CLIENT=postgres DATABASE_HOST=strapiDB DATABASE_PORT=5432 DATABASE_NAME=strapi DATABASE_USERNAME=strapi DATABASE_PASSWORD=strapi # Secrets APP_KEYS=toBeModified1,toBeModified2 API_TOKEN_SALT=tobemodified ADMIN_JWT_SECRET=tobemodified TRANSFER_TOKEN_SALT=tobemodified JWT_SECRET=tobemodified ENCRYPTION_KEY=tobemodified # Environment NODE_ENV=development ``` -------------------------------- ### Get Paginated List of Files (Offset Pagination) Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/api/rest/upload.md Example of using offset-based pagination with query parameters for skipping records and limiting results. The response meta object will reflect 'start' and 'limit' when this method is used. ```http GET /api/upload/files/page?pagination[start]=20&pagination[limit]=5&pagination[withCount]=false&filters[mime][$startsWith]=image/ ``` ```json { "data": [ // ... ], "meta": { "pagination": { "start": 20, "limit": 5 } } } ``` -------------------------------- ### Create New Strapi Project with Quickstart Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-code.txt This command initializes a new Strapi project with the quickstart option enabled for rapid development. ```bash npx create-strapi-app my-project --quickstart ``` -------------------------------- ### Create New Strapi Project Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-code.txt Creates a new Strapi application with the quickstart option enabled. This command initializes a new project with default settings. ```bash npx create-strapi-app@latest --quickstart ``` -------------------------------- ### Starting Strapi Server with Different Hosts Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/configurations/environment.md Demonstrates how to start the Strapi server with different host configurations using environment variables and yarn. ```bash yarn start # uses host 127.0.0.1 ``` ```bash NODE_ENV=production yarn start # uses host defined in .env. If not defined, uses 0.0.0.0 ``` ```bash HOST=10.0.0.1 NODE_ENV=production yarn start # uses host 10.0.0.1 ``` -------------------------------- ### Example .env file Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/deployment.md Example environment variables for host and port. ```env HOST=10.0.0.1 PORT=1338 ``` -------------------------------- ### Build and Start Strapi Instance Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-code.txt Builds the Strapi project and then starts the server. This is a prerequisite for creating a transfer token on the destination instance. ```bash yarn build && yarn start ``` ```bash npm run build && npm run start ``` -------------------------------- ### Get all documents in a specific locale - Request Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/api/rest/locale.md Example GET request to retrieve all documents for the 'fr' locale. ```http GET http://localhost:1337/api/restaurants?locale=fr ``` -------------------------------- ### Using env Helpers in Server Configuration Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-full.txt Demonstrates how to use the env helper and its typed methods to configure server settings like host, port, and application keys. Provides default values for host and port if not specified. ```javascript const { env } = require('@strapi/utils'); module.exports = { host: env('HOST', '0.0.0.0'), port: env.int('PORT', 1337), app: { keys: env.array('APP_KEYS'), }, }; ``` -------------------------------- ### Commit Message Examples (Good) Source: https://github.com/strapi/documentation/blob/main/git-rules.md Examples of well-formatted commit messages that start with an action verb and are specific. ```text Add initial AGENTS.md for repo and cms/cloud/snippets Update llms-code generator to add anchors by default Improve sidebar width stability to reduce layout shift Remove outdated Amplitude integration docs Fix typo in configuration section ``` -------------------------------- ### Get current user API response Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/features/users-permissions/rest-api.md Example JSON response for the 'Get current user' endpoint, showing user details. ```json { "id": 1, "documentId": "x74detpqybxw0bn6ormua5g2", "username": "testuser1", "email": "user@example.com", "provider": "local", "confirmed": true, "blocked": false, "createdAt": "2024-03-15T10:00:00.000Z", "updatedAt": "2024-03-15T10:00:00.000Z", "publishedAt": "2024-03-15T10:00:00.000Z" } ``` -------------------------------- ### Get a single type document in a specific locale Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/api/rest/locale.md Example of a GET request to retrieve a specific homepage document in French. ```HTTP GET /api/homepage?locale=fr ``` ```json { "data": { "id": 10, "documentId": "ukbpbnu8kbutpn98rsanyi50", "Title": "Page d'accueil", "Body": null, "createdAt": "2024-03-07T13:28:26.349Z", "updatedAt": "2024-03-07T13:28:26.349Z", "publishedAt": "2024-03-07T13:28:26.353Z", "locale": "fr" }, "meta": {} } ``` -------------------------------- ### Start Strapi Development Server Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-code.txt Navigate into your project directory and start the local development server. This command is used after the project is created. ```bash cd my-strapi-project && npm run develop ``` -------------------------------- ### Full configuration Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/configurations/server.md An example of a full server configuration file, demonstrating various available options beyond the minimal requirements. ```js module.exports = ({ env }) => ({ host: env('HOST', '0.0.0.0'), port: env.int('PORT', 1337), app: { keys: env.array('APP_KEYS'), }, socket: '/tmp/nginx.socket', // only use if absolutely required emitErrors: false, url: env('PUBLIC_URL', 'https://api.example.com'), proxy: { koa: env.bool('IS_PROXIED', true) }, cron: { enabled: env.bool('CRON_ENABLED', false), }, transfer: { remote: { enabled: false, }, }, logger: { updates: { enabled: false, }, startup: { enabled: false, }, }, }); ``` ```ts export default ({ env }) => ({ host: env('HOST', '0.0.0.0'), port: env.int('PORT', 1337), app: { keys: env.array('APP_KEYS'), }, socket: '/tmp/nginx.socket', // only use if absolutely required emitErrors: false, url: env('PUBLIC_URL', 'https://api.example.com'), proxy: { koa: env.bool('IS_PROXIED', true) }, cron: { enabled: env.bool('CRON_ENABLED', false), }, transfer: { remote: { enabled: false, }, }, logger: { updates: { enabled: false, }, startup: { enabled: false, }, }, }); ``` -------------------------------- ### Example query: Pagination by offset Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/api/graphql.md An example GraphQL query demonstrating pagination by offset using `start` and `limit` parameters. ```graphql { restaurants_connection(pagination: { start: 10, limit: 19 }) { nodes { documentId name } pageInfo { page pageSize pageCount total } } } ``` -------------------------------- ### Example API Call Source: https://github.com/strapi/documentation/blob/main/claude-plugins/inki/references/templates/feature-template.md Demonstrates how to make an API call related to the feature. ```bash curl https://example/... ``` -------------------------------- ### Get a collection type document in a specific locale Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/api/rest/locale.md Example of a GET request to retrieve a specific restaurant document in French, identified by its documentId. ```HTTP GET /api/restaurants/lr5wju2og49bf820kj9kz8c3?locale=fr ``` ```json { "data": [ { "id": 22, "documentId": "lr5wju2og49bf820kj9kz8c3", "Name": "Biscotte Restaurant", "Description": [ { "type": "paragraph", "children": [ { "type": "text", "text": "Bienvenue au restaurant Biscotte! Le Restaurant Biscotte propose une cuisine à base de produits frais et de qualité, souvent locaux, biologiques lorsque cela est possible, et toujours produits par des producteurs passionnés." } ] } ], // "locale": "fr" }, // ], "meta": { "pagination": { "page": 1, "pageSize": 25, "pageCount": 1, "total": 3 } } } ``` -------------------------------- ### Install AWS S3 provider Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/configurations/media-library-providers.md Example of installing the AWS S3 provider for the Media Library feature using Yarn or NPM. ```bash yarn add @strapi/provider-upload-aws-s3 ``` ```bash npm install @strapi/provider-upload-aws-s3 --save ``` -------------------------------- ### Minimal Bash Example Source: https://github.com/strapi/documentation/blob/main/claude-plugins/inki/references/templates/feature-template.md A minimal, focused example using bash commands. ```bash # minimal, focused example ``` -------------------------------- ### Install Local Upload Provider (NPM) Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-code.txt Use this command to install the local upload provider using NPM. ```bash npm install @strapi/provider-upload-local --save ``` -------------------------------- ### Find Documents by Name Filter Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-code.txt Use this to find documents where the 'name' field starts with a specific string. The example shows filtering restaurants by names starting with 'Pizzeria'. ```javascript await strapi.documents('api::restaurant.restaurant').findMany( { filters: { name: { $startsWith: 'Pizzeria' } } } ) ``` ```json [ { documentId: "j9k8l7m6n5o4p3q2r1s0tuvw", name: "Pizzeria Arrivederci", locale: "en", // default locale publishedAt: null, // draft version (default) // … }, // … ] ``` -------------------------------- ### Example PR Analysis Workflow Source: https://github.com/strapi/documentation/blob/main/claude-plugins/inki/references/prompts/shared/github-mcp-usage.md An example demonstrating the sequence of GitHub MCP tool calls to analyze a pull request, starting with fetching metadata and then changed files. ```tool_code 1. github:get_pull_request("strapi", "documentation", 1542) → Title: "Add MCP Server documentation" → Description: explains the feature 2. github:get_pull_request_files("strapi", "documentation", 1542) → docs/cms/features/mcp-server.md (added) → docs/cms/configurations/server.md (modified) 3. Proceed with analysis using the fetched data ``` -------------------------------- ### Example Extensions Folder Structure Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/plugins-development/plugins-extension.md Illustrates the directory structure for extending multiple plugins and their content types within the `./src/extensions` folder. ```bash /extensions /some-plugin-to-extend strapi-server.js|ts /content-types /some-content-type-to-extend schema.json /another-content-type-to-extend schema.json /another-plugin-to-extend strapi-server.js|ts ``` -------------------------------- ### Install Local Upload Provider (Yarn) Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-code.txt Use this command to install the local upload provider using Yarn. ```bash yarn add @strapi/provider-upload-local ``` -------------------------------- ### Get One Single Type in a Specific Locale (JSON) Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-code.txt Example response for retrieving a single type entry, showing its localized fields. The `Body` field is null in this example. ```json { "data": { "id": 10, "documentId": "ukbpbnu8kbutpn98rsanyi50", "Title": "Page d'accueil", "Body": null, "createdAt": "2024-03-07T13:28:26.349Z", "updatedAt": "2024-03-07T13:28:26.349Z", "publishedAt": "2024-03-07T13:28:26.353Z", "locale": "fr" }, "meta": {} } ``` -------------------------------- ### Configuration Example with File Path Source: https://github.com/strapi/documentation/blob/main/claude-plugins/inki/references/authoring/AGENTS.cms.configurations.md Include the specific file path in the code fence title for clarity, indicating where the configuration code should be placed. ```javascript ```javascript title="/config/server.js" // Server configuration code ``` ``` -------------------------------- ### Creating the plugin Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/plugins-development/create-a-plugin.md Command to initialize a new Strapi plugin using the Plugin SDK. ```bash yarn dlx @strapi/sdk-plugin init my-strapi-plugin ``` ```bash npx @strapi/sdk-plugin init my-strapi-plugin ``` -------------------------------- ### Using `useFetchClient` Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/migration/v4-to-v5/additional-resources/helper-plugin.md Example demonstrating how to use the `get` method from `useFetchClient`. ```tsx const { get } = useFetchClient(); const { data } = await get(requestURL); ``` -------------------------------- ### Install Strapi Client with NPM Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/api/client.md Install the Strapi Client library as a dependency using NPM. ```bash npm install @strapi/client ``` -------------------------------- ### Pull Request Title Examples (Good) Source: https://github.com/strapi/documentation/blob/main/git-rules.md Illustrative examples of acceptable pull request titles, including those starting with action verbs or specific feature noun phrases. ```text Checklist in SSO configuration documentation Document Service API intro rework: more details, updated structure Lifecycle functions: more details & examples of usage More details regarding image uploading [experimental] Allow setting a preferred AI toolbar default action Add AI tools page Add tip about nested page hierarchies in Content-type Builder documentation Add documentation about the strapi-plugin generate command Document auth fix for 5.24.0+ Add openapi.json route documentation (#2143) (#2159) ``` -------------------------------- ### Get Current Strapi Version Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-code.txt Check the current installed version of Strapi using the `-V` flag. ```sh $ npx @strapi/upgrade -V 4.15.1 ``` -------------------------------- ### Fetch data using useFetchClient Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-code.txt Example of fetching data using the get method from useFetchClient in v5. ```tsx const { get } = useFetchClient(); const { data } = await get(requestURL); ``` -------------------------------- ### MySQL Database Configuration Example Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-code.txt Example environment variables for configuring a MySQL database connection. ```dotenv # Database DATABASE_CLIENT=mysql DATABASE_HOST=127.0.0.1 DATABASE_PORT=3306 DATABASE_NAME=strapi DATABASE_USERNAME=strapi DATABASE_PASSWORD=strap1 DATABASE_SSL=false ``` -------------------------------- ### Query parameters Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/plugins-development/admin-fetch-client.md Example of passing query string parameters to a `get` request. ```js const { data } = await get('/content-manager/collection-types/api::article.article', { params: { page: 1, pageSize: 10, sort: 'title:asc', }, }); ``` -------------------------------- ### Get settings Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/configurations/database.md Example of using `strapi.store().get()` to retrieve a setting from the plugin store. ```js // strapi.store(object).get(object); // create reusable plugin store variable const pluginStore = strapi.store({ environment: strapi.config.environment, type: 'plugin', name: 'users-permissions' }); await pluginStore.get({ key: 'grant' }); ``` -------------------------------- ### Build and Verify Plugin Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/plugins-development/create-a-plugin.md Commands to build and verify a Strapi plugin before publishing. ```bash yarn build && yarn verify ``` ```bash npm run build && npm run verify ``` -------------------------------- ### JavaScript Configuration Example Source: https://github.com/strapi/documentation/blob/main/claude-plugins/inki/references/templates/configuration-template.md Example of a minimal JavaScript configuration file for a Strapi application. It demonstrates how to use environment variables with a default value. ```javascript module.exports = ({ env }) => ({ optionName: env('ENV_VAR', 'default'), }); ``` -------------------------------- ### Creating API Validators Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/strapi-utils.md Example of using `createAPIValidators` to get a set of validator methods scoped to a model. ```js const validators = validate.createAPIValidators({ getModel: strapi.getModel.bind(strapi), }); ``` -------------------------------- ### Complete AWS S3 Provider Configuration Example Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-code.txt A comprehensive example demonstrating the configuration of the AWS S3 media library provider in Strapi. It includes settings for base URL, root path, S3 credentials, region, bucket parameters, and advanced provider configurations like checksum algorithm, overwrite prevention, storage class, encryption, tags, and multipart upload. ```javascript module.exports = ({ env }) => ({ upload: { config: { provider: 'aws-s3', providerOptions: { baseUrl: env('CDN_URL'), rootPath: env('CDN_ROOT_PATH'), s3Options: { credentials: { accessKeyId: env('AWS_ACCESS_KEY_ID'), secretAccessKey: env('AWS_ACCESS_SECRET'), }, region: env('AWS_REGION'), params: { ACL: 'private', signedUrlExpires: 15 * 60, Bucket: env('AWS_BUCKET'), }, }, providerConfig: { checksumAlgorithm: 'CRC64NVME', preventOverwrite: true, storageClass: 'INTELLIGENT_TIERING', encryption: { type: 'aws:kms', kmsKeyId: env('AWS_KMS_KEY_ID'), }, tags: { application: 'strapi', environment: env('NODE_ENV'), }, multipart: { partSize: 10 * 1024 * 1024, queueSize: 4, }, }, }, }, }, }); ``` -------------------------------- ### Strapi Admin UI Redux Store Example Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-code.txt This comprehensive example showcases reading state, dispatching actions, and subscribing to store changes within a Strapi admin panel component. It requires React and Redux setup. ```typescript import { Main } from '@strapi/design-system'; import { Button, Box, Typography, Flex } from '@strapi/design-system'; import { useSelector, useDispatch, useStore } from 'react-redux'; import { useEffect, useState } from 'react'; const HomePage = () => { const dispatch = useDispatch(); const store = useStore(); // Reading state const currentTheme = useSelector( (state: any) => state.admin_app?.theme?.currentTheme ); const currentLocale = useSelector( (state: any) => state.admin_app?.language?.locale ); const isAuthenticated = useSelector((state: any) => !!state.admin_app?.token); const availableLocales = useSelector( (state: any) => state.admin_app?.language?.localeNames || {} ); // Dispatching actions const handleToggleTheme = () => { const newTheme = currentTheme === 'light' ? 'dark' : currentTheme === 'dark' ? 'system' : 'light'; dispatch({ type: 'admin/setAppTheme', payload: newTheme } as any); }; const handleChangeLocale = (locale: string) => { dispatch({ type: 'admin/setLocale', payload: locale } as any); }; // Subscribing to store changes const [storeChangeCount, setStoreChangeCount] = useState(0); const [lastChange, setLastChange] = useState(''); useEffect(() => { const unsubscribe = store.subscribe(() => { setStoreChangeCount((prev) => prev + 1); setLastChange(new Date().toLocaleTimeString()); }); return () => unsubscribe(); }, [store]); return (
Redux Store Examples Reading state Current Theme: {currentTheme || 'system'} Current Locale: {currentLocale || 'en'} Authentication Status:{' '} {isAuthenticated ? 'Authenticated' : 'Not Authenticated'} Dispatching actions {Object.keys(availableLocales).map((locale) => ( ))} Subscribing to store changes Store has changed {storeChangeCount} time(s) {lastChange && ( Last change at: {lastChange} )}
); }; export { HomePage }; ``` -------------------------------- ### Response types Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/plugins-development/admin-fetch-client.md Example of handling a non-JSON response (blob) using the `responseType` option with `get`. ```js import { useFetchClient } from '@strapi/strapi/admin'; const DownloadButton = () => { const { get } = useFetchClient(); const downloadFile = async (url) => { const { data: blob, status, headers } = await get(url, { responseType: 'blob' }); // Process the blob, for example to trigger a file download }; }; ``` ```ts import { useFetchClient } from '@strapi/strapi/admin'; const DownloadButton = () => { const { get } = useFetchClient(); const downloadFile = async (url: string) => { const { data: blob, status, headers } = await get(url, { responseType: 'blob' }); // Process the blob, for example to trigger a file download }; }; ``` -------------------------------- ### Install Strapi Client with pnpm Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/api/client.md Install the Strapi Client library as a dependency using pnpm. ```bash pnpm add @strapi/client ``` -------------------------------- ### Create a New Strapi Project Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-code.txt Run this command to initialize a new Strapi project. Ensure you have Node.js and npm installed. ```bash npx create-strapi@latest my-strapi-project ``` -------------------------------- ### Using `strapi.compile()` Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/typescript/development.md Example of using `strapi.compile()` to start a Strapi instance, which automatically detects and compiles TypeScript code. ```js const strapi = require('@strapi/strapi'); strapi.compile().then(appContext => strapi(appContext).start()); ``` -------------------------------- ### Start Strapi Console Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/cli.md Opens a Node.js REPL with access to all Strapi APIs. Press Ctrl-C twice to stop the server. ```bash strapi console ``` -------------------------------- ### ./server.js Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/typescript/development.md Example of starting Strapi programmatically using `strapi.createStrapi()` with the `distDir` parameter to specify the compiled code location. ```js const strapi = require('@strapi/strapi'); const app = strapi.createStrapi({ distDir: './dist' }); app.start(); ``` -------------------------------- ### Core Service Implementation Examples Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/backend-customization/services.md Demonstrates three ways to implement a service: creating an entirely new custom service, wrapping an existing core service to add custom logic, and replacing a core service. ```js const { createCoreService } = require('@strapi/strapi').factories; module.exports = createCoreService('api::restaurant.restaurant', ({ strapi }) => ({ // Method 1: Creating an entirely new custom service async exampleService(...args) { let response = { okay: true } if (response.okay === false) { return { response, error: true } } return response }, // Method 2: Wrapping a core service (leaves core logic in place) async find(...args) { // Calling the default core controller const { results, pagination } = await super.find(...args); // some custom logic results.forEach(result => { result.counter = 1; }); return { results, pagination }; }, // Method 3: Replacing a core service async findOne(documentId, params = {}) { return strapi.documents('api::restaurant.restaurant').findOne({ documentId, // Use super to keep core fetch parameter formatting ...super.getFetchParams(params), }); } })); ``` ```ts import { factories } from '@strapi/strapi'; export default factories.createCoreService('api::restaurant.restaurant', ({ strapi }) => ({ // Method 1: Creating an entirely custom service async exampleService(...args) { let response = { okay: true } if (response.okay === false) { return { response, error: true } } return response }, // Method 2: Wrapping a core service (leaves core logic in place) async find(...args) { // Calling the default core controller const { results, pagination } = await super.find(...args); // some custom logic results.forEach(result => { result.counter = 1; }); return { results, pagination }; }, // Method 3: Replacing a core service async findOne(documentId, params = {}) { return strapi.documents('api::restaurant.restaurant').findOne({ documentId, // Use super to keep core fetch parameter formatting ...super.getFetchParams(params) }) as any; } })); ``` -------------------------------- ### $startsWith Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/api/query-engine/filtering.md Example of using the $startsWith operator to find entries where an attribute starts with the input value. ```js const entries = await strapi.db.query('api::article.article').findMany({ where: { title: { $startsWith: 'ABCD', }, }, }); ``` -------------------------------- ### Linking the plugin to your project Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/plugins-development/create-a-plugin.md Commands to link the newly created plugin to an existing Strapi project for development. ```bash cd /path/to/strapi/project yarn dlx yalc add --link my-strapi-plugin && yarn install ``` ```bash cd /path/to/strapi/project npx yalc add --link my-strapi-plugin && npm install ``` -------------------------------- ### Installation Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/plugins/documentation.md Commands to install the Documentation plugin using yarn or npm. ```bash yarn add @strapi/plugin-documentation ``` ```bash npm install @strapi/plugin-documentation ``` -------------------------------- ### Custom server.js file Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/deployment.md Example of a server.js file to run Strapi using `node server.js` instead of `npm run start`. ```js const strapi = require('@strapi/strapi'); strapi.createStrapi(/* {...} */).start(); ``` -------------------------------- ### Delete Documents by Filter in Strapi Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-code.txt Use this to delete documents that match specific filter criteria. The example shows deleting documents starting with 'Pizzeria'. ```JavaScript await strapi.documents('api::restaurant.restaurant').delete( { filters: { name: { $startsWith: 'Pizzeria' }}} ) ``` -------------------------------- ### Example Plugin Extensions Folder Structure Source: https://github.com/strapi/documentation/blob/main/docusaurus/static/llms-full.txt Illustrates the typical directory layout for extending Strapi plugins, showing how to target specific plugins and their content types. ```bash /extensions /some-plugin-to-extend strapi-server.js|ts /content-types /some-content-type-to-extend schema.json /another-content-type-to-extend schema.json /another-plugin-to-extend strapi-server.js|ts ``` -------------------------------- ### Run Strapi application Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/installation/cli.md Start the Strapi development server using NPM. ```bash npm run develop ``` -------------------------------- ### Pagination Source: https://github.com/strapi/documentation/blob/main/docusaurus/docs/cms/api/document-service/sort-pagination.md Example request to paginate documents, limiting to 10 results starting from the first item. ```js const documents = await strapi.documents("api::article.article").findMany({ limit: 10, start: 0 }); ``` ```json [ { "documentId": "cjld2cjxh0000qzrmn831i7rn", "title": "Test Article", "slug": "test-article", "body": "Test 1" // ... }, { "documentId": "cjld2cjxh0001qzrm5q1j5q7m", "title": "Test Article 2", "slug": "test-article-2", "body": "Test 2" // ... } // ... (8 more) ] ```