### Install Documentation Plugin Source: https://docs-v4.strapi.io/llms-v4-full.txt Install the Documentation plugin using the provided command. Once installed, starting the application will automatically generate API documentation. ```bash npm run strapi install documentation ``` -------------------------------- ### Strapi CLI: Create New Project with Quickstart Source: https://docs-v4.strapi.io/llms-v4-full.txt Creates a new Strapi project using the quickstart system for faster setup. The application will start automatically after creation. ```bash strapi new --quickstart ``` -------------------------------- ### Server Startup Commands Source: https://docs-v4.strapi.io/dev-docs/configurations/environment Examples of starting 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 ``` -------------------------------- ### Ruby Setup: Create Directory and File Source: https://docs-v4.strapi.io/llms-v4-full.txt Commands to create a new directory for a Ruby application and an empty script file. Assumes Ruby is installed. ```bash mkdir ruby-app && cd ruby-app touch script.rb ``` -------------------------------- ### Create a new Strapi project with quickstart Source: https://docs-v4.strapi.io/dev-docs/api/rest/guides/understanding-populate Use this command to quickly set up a new Strapi project with a default SQLite database and admin panel. It's a great starting point for trying out Strapi features. ```bash npx create-strapi-app my-project --quickstart ``` -------------------------------- ### Strapi CLI: Create New Project with Quickstart (No Run) Source: https://docs-v4.strapi.io/llms-v4-full.txt Creates a new Strapi project using the quickstart system but prevents the application from starting automatically after creation. ```bash strapi new --quickstart --no-run ``` -------------------------------- ### Run qs Locally Source: https://docs-v4.strapi.io/snippets/qs-for-query-body This example demonstrates how to run the `qs` library locally on your machine to build query URLs. Ensure you have the library installed. ```javascript const qs = require('qs'); const query = { filters: { name: { $contains: 'Strapi', }, description: { $containsi: 'api', }, }, sort: { name: 'asc', }, populate: { category: true, author: { fields: ['name', 'email'], }, }, }; const queryString = qs.stringify(query); console.log(queryString); // Expected output: filters%5Bname%5D%5B%24contains%5D=Strapi&filters%5Bdescription%5D%5B%24containsi%5D=api&sort%5Bname%5D=asc&populate%5Bcategory%5D=true&populate%5Bauthor%5D%5Bfields%5D%5B0%5D=name&populate%5Bauthor%5D%5Bfields%5D%5B1%5D=email ``` -------------------------------- ### Create Strapi App with Quickstart Source: https://docs-v4.strapi.io/dev-docs/quick-start Use this command to create a new Strapi project with a SQLite database and skip the manual setup. It also initiates the Strapi Cloud account creation process. ```bash npx create-strapi-app@4.25.19 my-strapi-project --quickstart ``` -------------------------------- ### Setup Strapi dependencies Source: https://docs-v4.strapi.io/dev-docs/migration/v3-to-v4/code/strapi-global Command to install all dependencies after cloning the Strapi repository. This is required before running the Storybook instance. ```bash cd strapi && yarn setup ``` -------------------------------- ### Create a new Strapi project Source: https://docs-v4.strapi.io/dev-docs/data-management/transfer Use this command to initialize a new Strapi project with quickstart settings. Ensure you have Node.js and npm/yarn installed. ```bash npx create-strapi-app@latest --quickstart ``` -------------------------------- ### Ruby Setup: Install HTTParty Gem Source: https://docs-v4.strapi.io/llms-v4-full.txt Commands to set up a Ruby project with the HTTParty gem for making HTTP requests. Includes creating a Gemfile and installing dependencies. ```bash source "https://rubygems.org" gem "httparty" ``` ```bash bundle install ``` -------------------------------- ### Full Go Application Example Source: https://docs-v4.strapi.io/dev-docs/integrations/go A complete Go program demonstrating GET, POST, and PUT requests to the Strapi API. This includes functions for fetching data, creating new entries, and updating existing ones. ```go package main import ( "bytes" "encoding/json" "fmt" "io/ioutil" "log" "net/http" ) func main() { //getD() //postD() putD() } func getD() { fmt.Println("Getting data...") resp, error := http.Get("http://localhost:1337/api/restaurants") if error != nil { fmt.Printf("The HTTP request failed with error %s\n", error) } else { data, _ := ioutil.ReadAll(resp.Body) fmt.Println(string(data)) } } func postD() { fmt.Println("Posting data...") // Encode the data postRest, _ := json.Marshal(map[string]string{ "name": "Nwanyi Igbo", "description": "This is a very nice place to eat native soup", }) responseBody := bytes.NewBuffer(postRest) resp, error := http.Post("http://localhost:1337/api/restaurants", "application/json", responseBody) // Handle Error if error != nil { log.Fatalf("An Error Occured %v", error) } defer resp.Body.Close() // Read the response body body, error := ioutil.ReadAll(resp.Body) if error != nil { log.Fatalln(error) } fmt.Println(string(body)) } func putD() { putRest, _ := json.Marshal(map[string]string{ "name": "Restaurant Homes", }) client := &http.Client{} url := "http://localhost:1337/api/restaurants/1" req, error := http.NewRequest(http.MethodPut, url, bytes.NewBuffer(putRest)) req.Header.Set("Content-Type", "application/json") if error != nil { log.Fatal(error) } resp, error := client.Do(req) if error != nil { log.Fatal(error) } defer resp.Body.Close() body, error := ioutil.ReadAll(resp.Body) if error != nil { log.Fatal(error) } fmt.Println(string(body)) } ``` -------------------------------- ### Install 11ty with npm Source: https://docs-v4.strapi.io/dev-docs/integrations/11ty Installs Eleventy and initializes a new project using npm. ```bash npm init -y npm install @11ty/eleventy ``` -------------------------------- ### Install 11ty with Yarn Source: https://docs-v4.strapi.io/dev-docs/integrations/11ty Installs Eleventy and initializes a new project using Yarn. ```bash yarn init -y yarn add @11ty/eleventy ``` -------------------------------- ### Configure Windows Start Script Source: https://docs-v4.strapi.io/dev-docs/deployment Use the 'cross-env' package to manage environment variables for starting your server on Windows. Define a 'start:win' script in your package.json to set NODE_ENV to 'production' and run the start command. ```bash npm install cross-env ``` ```json "start:win": "cross-env NODE_ENV=production npm start" ``` -------------------------------- ### Enable and Start Webhook Service Source: https://docs-v4.strapi.io/llms-v4-full.txt Enables the webhook service to start on system boot and starts the service immediately. ```bash sudo systemctl enable webhook.service sudo systemctl start webhook ``` -------------------------------- ### Enable and Start Webhook Service Source: https://docs-v4.strapi.io/dev-docs/deployment/digitalocean Enables the webhook service to start automatically on system boot and then starts the service immediately. ```bash sudo systemctl enable webhook.service sudo systemctl start webhook ``` -------------------------------- ### Run Windows Start Script Source: https://docs-v4.strapi.io/dev-docs/deployment Execute the 'start:win' script to start your Strapi server in production mode on Windows. ```bash npm run start:win ``` -------------------------------- ### Start Strapi with PM2 using NPM (Production) Source: https://docs-v4.strapi.io/dev-docs/deployment/process-manager Starts a Strapi application using PM2 with NPM. This command specifies the application name and the 'start' script. ```bash pm2 start npm --name your-app-name -- run start ``` -------------------------------- ### Install passport-okta-oauth20 with npm Source: https://docs-v4.strapi.io/dev-docs/configurations/sso Install the Okta OAuth2 strategy package using npm. ```bash npm install --save passport-okta-oauth20 ``` -------------------------------- ### Generic Implementation Example for a GET Request Source: https://docs-v4.strapi.io/llms-v4-full.txt This example shows a generic implementation allowing only a GET request on the '/restaurants' path, handled by the core 'find' controller without authentication. ```javascript export default { routes: [ { method: 'GET', path: '/restaurants', handler: 'restaurant.find', config: { auth: false, }, }, ], }; ``` -------------------------------- ### Install Flutter Dependencies Source: https://docs-v4.strapi.io/llms-v4-full.txt Run `flutter pub get` to download and install the dependencies listed in your `pubspec.yaml` file. ```bash flutter pub get ``` -------------------------------- ### Install Dart Dependencies Source: https://docs-v4.strapi.io/llms-v4-full.txt Run `dart pub get` to download and install the dependencies specified in your `pubspec.yaml` file. ```bash dart pub get ``` -------------------------------- ### Example GET Response Source: https://docs-v4.strapi.io/dev-docs/integrations/flutter This is an example of the JSON response you might receive when fetching restaurant data from the Strapi API. ```json [ { "id": 1, "name": "Biscotte Restaurant", "description": "Welcome to Biscotte restaurant! Restaurant Biscotte offers a cuisine based on fresh, quality products, often local, organic when possible, and always produced by passionate producers.", "created_by": { "id": 1, "firstname": "Paul", "lastname": "Bocuse", "username": null }, "updated_by": { "id": 1, "firstname": "Paul", "lastname": "Bocuse", "username": null }, "created_at": "2020-07-31T11:37:16.964Z", "updated_at": "2020-07-31T11:37:16.975Z", "categories": [ { "id": 1, "name": "French Food", "created_by": 1, "updated_by": 1, "created_at": "2020-07-31T11:36:23.164Z", "updated_at": "2020-07-31T11:36:23.172Z" } ] } ] ``` -------------------------------- ### Example GET Response for Restaurants Source: https://docs-v4.strapi.io/dev-docs/integrations/dart This is a sample JSON response structure for a GET request to the '/restaurants' endpoint, showing a list of restaurant objects. ```json [ { "id": 1, "name": "Biscotte Restaurant", "description": "Welcome to Biscotte restaurant! Restaurant Biscotte offers a cuisine based on fresh, quality products, often local, organic when possible, and always produced by passionate producers.", "created_by": { "id": 1, "firstname": "Paul", "lastname": "Bocuse", "username": null }, "updated_by": { "id": 1, "firstname": "Paul", "lastname": "Bocuse", "username": null }, "created_at": "2020-07-31T11:37:16.964Z", "updated_at": "2020-07-31T11:37:16.975Z", "categories": [ { "id": 1, "name": "French Food", "created_by": 1, "updated_by": 1, "created_at": "2020-07-31T11:36:23.164Z", "updated_at": "2020-07-31T11:36:23.172Z" } ] } ] ``` -------------------------------- ### Example of Updated Server Configuration Source: https://docs-v4.strapi.io/dev-docs/migration/v4/migration-guide-4.0.0-to-4.0.6 This example shows the complete server configuration including the 'keys' setting for session management. ```javascript module.exports = ({ env }) => ({ host: env('HOST', '0.0.0.0'), port: env.int('PORT', 1337), app: { keys: env.array("APP_KEYS"), }, // ... }); ``` -------------------------------- ### Example Response for Get Entries Source: https://docs-v4.strapi.io/dev-docs/api/rest This is an example of a successful response when retrieving a list of entries from a collection type. It includes the data and meta information. ```json { "data": [ { "id": 1, "attributes": { "title": "Restaurant A", "description": "Restaurant A's description" }, "meta": { "availableLocales": [] } }, { "id": 2, "attributes": { "title": "Restaurant B", "description": "Restaurant B's description" }, "meta": { "availableLocales": [] } } ], "meta": {} } ``` -------------------------------- ### Example Response with Pagination Meta Source: https://docs-v4.strapi.io/dev-docs/api/rest/sort-pagination This is an example of a response that includes pagination metadata, showing the current start, limit, and total number of entries available. ```JSON { "data": [ // ... ], "meta": { "pagination": { "start": 0, "limit": 10, "total": 42 } } } ``` -------------------------------- ### Example Request: First 10 Entries Source: https://docs-v4.strapi.io/dev-docs/api/rest/sort-pagination This example demonstrates how to fetch the first 10 articles using the `pagination[start]` and `pagination[limit]` query parameters. ```HTTP GET /api/articles?pagination[start]=0&pagination[limit]=10 ``` -------------------------------- ### Example Response for Get Single Entry Source: https://docs-v4.strapi.io/dev-docs/api/rest This is an example of a successful response when retrieving a single entry by its ID. It includes the entry's attributes and meta information. ```json { "data": { "id": 1, "attributes": { "title": "Restaurant A", "description": "Restaurant A's description" }, "meta": { "availableLocales": [] } }, "meta": {} } ``` -------------------------------- ### Field Selection Example Source: https://docs-v4.strapi.io/dev-docs/api/rest/populate-select This example demonstrates how to use the `fields` parameter to retrieve only specific fields from a query. It shows both the GET request and the expected response structure. ```APIDOC ## GET /api/users?fields[0]=title&fields[1]=body ### Description Returns only the 'title' and 'body' fields for user entries. ### Method GET ### Endpoint `/api/users?fields[0]=title&fields[1]=body` ### Response #### Success Response (200) - **data** (array) - Contains the array of user objects with selected fields. - **id** (integer) - The ID of the user. - **attributes** (object) - Contains the selected fields of the user. - **title** (string) - The title of the user. - **body** (string) - The body content of the user. ### Response Example ```json { "data": [ { "id": 1, "attributes": { "title": "test1", "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit." } } ], "meta": { // ... } } ``` ``` -------------------------------- ### Create and Open .env File Source: https://docs-v4.strapi.io/dev-docs/deployment/digitalocean Navigate to your project directory and create or open the .env file for environment-specific configurations. ```bash cd ~/your-project sudo nano .env ``` -------------------------------- ### Build Admin Panel and Start Servers (Vanilla JS) Source: https://docs-v4.strapi.io/llms-v4-full.txt Navigate to the Strapi project root and run this command to build the admin panel and start the server(s) after plugin code generation. ```bash cd ../../.. strapi build --clean strapi develop ``` -------------------------------- ### Get Strapi Version Source: https://docs-v4.strapi.io/dev-docs/cli Prints the current globally installed Strapi version. ```bash strapi version ``` -------------------------------- ### Strapi Instance Setup and Basic Test Source: https://docs-v4.strapi.io/dev-docs/testing This code sets up the Strapi instance for testing and includes a basic test to ensure Strapi is defined. It requires helper functions for setup and cleanup. ```javascript const fs = require('fs'); const { setupStrapi, cleanupStrapi } = require("./helpers/strapi"); beforeAll(async () => { await setupStrapi(); }); afterAll(async () => { await cleanupStrapi(); }); it("strapi is defined", () => { expect(strapi).toBeDefined(); }); ``` -------------------------------- ### Basic Server Configuration Source: https://docs-v4.strapi.io/dev-docs/configurations/guides/access-configuration-values Example of a simple server configuration file in JavaScript. ```javascript module.exports = { host: '0.0.0.0', }; ``` -------------------------------- ### GET Request with Axios Source: https://docs-v4.strapi.io/dev-docs/integrations/next-js Example of fetching all restaurants from the Strapi API using Axios. ```javascript import axios from 'axios'; axios.get('http://localhost:1337/api/restaurants').then(response => { console.log(response.data); }); ``` -------------------------------- ### Fetch All Restaurants using GET Request Source: https://docs-v4.strapi.io/dev-docs/integrations/dart This example demonstrates how to perform a GET request to fetch all entries from the 'restaurants' collection type. Ensure 'find' permission is enabled for the 'restaurant' collection. ```dart Map headers = { 'Content-Type':'application/json', 'Accept': 'application/json' }; var response = await http.get( 'http://localhost:1337/restaurants', headers: headers ); print(response.body) ``` -------------------------------- ### Example Response: Populating Only Dynamic Zone Source: https://docs-v4.strapi.io/dev-docs/api/rest/guides/understanding-populate This is an example response from a GET request to `/api/articles?populate[0]=blocks`. It shows the 'blocks' dynamic zone and its included components, but not their nested fields. ```json { "data": [ { "id": 1, "attributes": { "title": "Here's why you have to try basque cuisine, according to a basque chef", "slug": "here-s-why-you-have-to-try-basque-cuisine-according-to-a-basque-chef", "createdAt": "2021-11-09T13:33:19.948Z", "updatedAt": "2023-06-02T10:57:19.584Z", "publishedAt": "2022-09-22T09:30:00.208Z", "locale": "en", "ckeditor_content": "…" // truncated content "blocks": [ { "id": 2, "__component": "blocks.related-articles" }, { "id": 2, "__component": "blocks.cta-command-line", "theme": "primary", "title": "Want to give a try to a Strapi starter?", "text": "❤️", "commandLine": "git clone https://github.com/strapi/nextjs-corporate-starter.git" } ] } }, { "id": 2, // … }, { "id": 3, // … }, { "id": 4, // … } ], "meta": { "pagination": { "page": 1, "pageSize": 25, "pageCount": 1, "total": 4 } } } ``` -------------------------------- ### Example Extension Folder Structure Source: https://docs-v4.strapi.io/llms-v4-full.txt Illustrates the directory structure for extending multiple plugins and their content types. ```bash /extensions /some-plugin-to-extend strapi-server.js|ts /content-types /some-content-type-to-extend model.json /another-content-type-to-extend model.json /another-plugin-to-extend strapi-server.js|ts ``` -------------------------------- ### Example Request: Populating Only Dynamic Zone Source: https://docs-v4.strapi.io/dev-docs/api/rest/guides/understanding-populate This example demonstrates a GET request to the `/api/articles` endpoint with the `populate[0]=blocks` parameter. This populates only the 'blocks' dynamic zone, going one level deep. ```http GET /api/articles?populate[0]=blocks ``` -------------------------------- ### GET Request with Fetch API Source: https://docs-v4.strapi.io/dev-docs/integrations/next-js Example of fetching all restaurants from the Strapi API using the Fetch API. ```javascript fetch('http://localhost:1337/api/restaurants', { method: 'GET', headers: { 'Content-Type': 'application/json', }, }) .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### Create an 11ty app and install Eleventy Source: https://docs-v4.strapi.io/llms-v4-full.txt This snippet shows how to create a package.json file and install Eleventy as a project dependency for an 11ty application. ```bash npm install --save-dev @11ty/eleventy ``` -------------------------------- ### Custom Email Service with Nodemailer (JavaScript) Source: https://docs-v4.strapi.io/dev-docs/backend-customization/services Create a reusable email service using Nodemailer. This example sets up an SMTP transporter and defines a `sendNewsletter` function. Requires Nodemailer to be installed (`npm install nodemailer`). ```javascript const { createCoreService } = require('@strapi/strapi').factories; const nodemailer = require('nodemailer'); // Requires nodemailer to be installed (npm install nodemailer) // Create reusable transporter object using SMTP transport. const transporter = nodemailer.createTransport({ service: 'Gmail', auth: { user: 'user@gmail.com', pass: 'password', }, }); module.exports = createCoreService('api::restaurant.restaurant', ({ strapi }) => ({ sendNewsletter(from, to, subject, text) { // Setup e-mail data. const options = { from, to, subject, text, }; // Return a promise of the function that sends the email. return transporter.sendMail(options); }, })); ``` -------------------------------- ### Project Structure with Starter CLI Source: https://docs-v4.strapi.io/llms-v4-full.txt Illustrates the directory structure of a Strapi project created using the starter CLI, featuring separate frontend and backend folders. ```sh my-project ├─── frontend # starter folder ├─── backend # template folder, has the default structure of a project └─── node_modules ``` -------------------------------- ### Navigate and Start Strapi Project Source: https://docs-v4.strapi.io/dev-docs/deployment/azure Change directory into the newly created Strapi project and start the development server. This command also builds the Admin panel. ```bash # Change directory cd mystrapiapp # Temporary start (will build the Admin panel) yarn develop ``` -------------------------------- ### Example response with locale information Source: https://docs-v4.strapi.io/dev-docs/plugins/i18n This is an example response from a GET request that includes locale-specific fields like 'locale' and 'localizations'. The 'locale' field indicates the language of the entry, and 'localizations' can be populated to include related localized entries. ```json { "data": [ { "id": 4, "attributes": { "name": "Can Alegria", "description": "description in French", "locale": "fr", "createdAt": "2021-10-28T15:24:42.129Z", "publishedAt": "2021-10-28T15:24:42.129Z" } }, { "id": 8, "attributes": { "name": "She's Cake", "description": "description in French", "locale": "fr", "createdAt": "2021-10-28T16:17:42.129Z", "publishedAt": "2021-10-28T16:18:24.126Z" } } ], "meta": { "pagination": { "page": 1, "pageSize": 25, "pageCount": 2, "total": 2 } } } ``` -------------------------------- ### Configure Email Provider (Sendmail) Source: https://docs-v4.strapi.io/llms-v4-full.txt Example configuration for the Sendmail email provider in Strapi. This uses local Sendmail installation. ```javascript module.exports = ({ env }) => ({ email: { provider: '@strapi/provider-email-sendmail', providerOptions: { transportOptions: { host: env('MAIL_HOST', 'smtp.example.com'), port: env.int('MAIL_PORT', 587), secure: env.bool('MAIL_SECURE', false), auth: { user: env('MAIL_USERNAME'), pass: env('MAIL_PASSWORD'), }, }, }, settings: { defaultFrom: env('MAIL_FROM_EMAIL'), defaultReplyTo: env('MAIL_REPLY_TO'), }, }, }); ``` -------------------------------- ### Build and start Strapi instance (NPM) Source: https://docs-v4.strapi.io/dev-docs/data-management/transfer Build and start a Strapi instance using NPM. This command is typically run on the target instance before creating a transfer token. ```bash npm run build && npm run start ``` -------------------------------- ### Custom Email Service with Nodemailer (TypeScript) Source: https://docs-v4.strapi.io/dev-docs/backend-customization/services Implement a custom email service using TypeScript and Nodemailer. This example configures an SMTP transporter and provides a `sendNewsletter` function for sending emails. Ensure Nodemailer is installed (`npm install nodemailer`). ```typescript import { factories } from '@strapi/strapi'; const nodemailer = require('nodemailer'); // Requires nodemailer to be installed (npm install nodemailer) // Create reusable transporter object using SMTP transport. const transporter = nodemailer.createTransport({ service: 'Gmail', auth: { user: 'user@gmail.com', pass: 'password', }, }); export default factories.createCoreService('api::restaurant.restaurant', ({ strapi }) => ({ sendNewsletter(from, to, subject, text) { // Setup e-mail data. const options = { from, to, subject, text, }; // Return a promise of the function that sends the email. return transporter.sendMail(options); }, })); ``` -------------------------------- ### Configure Core Router with Policies, Middlewares, and Public Availability Source: https://docs-v4.strapi.io/llms-v4-full.txt Example demonstrating how to configure policies, middlewares, and public availability for a core router using the 'config' option. ```javascript import { createCoreRouter } from '@strapi/strapi'; export default createCoreRouter('api::restaurant.restaurant', { config: { find: { policies: [ 'api::restaurant.is-owner', { name: 'global::is-owner', // config: { // ownerField: 'user', // }, }, ], }, findOne: { middlewares: [ 'api::restaurant.is-owner', { name: 'global::is-owner', // config: { // ownerField: 'user', // }, }, ], }, create: { auth: { enabled: false, }, }, update: { auth: { enabled: false, }, }, delete: { auth: { enabled: false, }, }, }, }); ``` -------------------------------- ### Dart HTTP Request Example Source: https://docs-v4.strapi.io/llms-v4-full.txt This Dart code snippet demonstrates how to make GET, POST, and PUT requests to a Strapi API using the 'http' package. It includes examples for fetching all restaurants, creating a new one, and updating an existing one. ```dart class Restaurant { static String api_url = 'http://localhost:1337'; static Map headers = { 'Content-Type':'application/json', 'Accept': 'application/json' }; void all() async { var response = await http.get('${api_url}/restaurants', headers: headers); print(response.body); } void create(name, description, category) async { final data = jsonEncode({ 'name': name, 'description': description, 'categories': category }); var response = await http.post('${api_url}/restaurants', headers: headers, body: data); } void update(id, params) async { final data = jsonEncode({ 'categories': params['categories'] }); var response = await http.put("${api_url}/restaurants/${id}", headers: headers, body: data); } } void main() { var restaurant = Restaurant(); restaurant.update(2, {'categories': [2]}); } ``` -------------------------------- ### Install Documentation Plugin with Yarn Source: https://docs-v4.strapi.io/dev-docs/plugins/documentation Use this command to install the Documentation plugin using Yarn. ```bash yarn strapi install documentation ``` -------------------------------- ### Create a PHP file Source: https://docs-v4.strapi.io/dev-docs/integrations/php Use the `touch` command to create a new PHP file. Ensure PHP is installed on your system. ```bash touch strapi.php ``` -------------------------------- ### Install Documentation Plugin with NPM Source: https://docs-v4.strapi.io/dev-docs/plugins/documentation Use this command to install the Documentation plugin using NPM. ```bash npm run strapi install documentation ``` -------------------------------- ### Configure 11ty Project Source: https://docs-v4.strapi.io/dev-docs/integrations/11ty Sets up Eleventy with plugins, transforms, and directory configurations. Includes HTML minification and an error overlay plugin. ```javascript const HtmlMin = require('html-minifier'); const ErrorOverlay = require('eleventy-plugin-error-overlay'); module.exports = eleventyConfig => { eleventyConfig.setTemplateFormats(['md']); eleventyConfig.addPlugin(ErrorOverlay); eleventyConfig.addTransform('htmlmin', (content, outputPath) => { if (outputPath.endsWith('.html')) { let minified = HtmlMin.minify(content, { useShortDoctype: true, removeComments: true, collapseWhitespace: true, }); return minified; } return content; }); return { dir: { input: 'src', output: 'dist', includes: '_templates', data: '_data', }, jsDataFileSuffix: '.data', }; }; ``` -------------------------------- ### Example Request with Filters and Populate Source: https://docs-v4.strapi.io/dev-docs/api/rest/populate-select Demonstrates how to construct a GET request to fetch articles, populating their categories, sorting them by name, and filtering by category name. ```http GET /api/articles?populate[categories][sort][0]=name%3Aasc&populate[categories][filters][name][$eq]=Cars ``` -------------------------------- ### Example v4 Controller (With Customization) Source: https://docs-v4.strapi.io/dev-docs/migration/v3-to-v4/code/controllers A complete example of a v4 controller file demonstrating customization. The `find` action is overridden to add custom logic before and after calling the default core action. ```javascript const { createCoreController } = require('@strapi/strapi').factories; module.exports = createCoreController('api::api-name.content-type-name', ({ strapi }) => ({ // wrap a core action, leaving core logic in place async find(ctx) { // some custom logic here ctx.query = { ...ctx.query, local: 'en' } // calling the default core action with super const { data, meta } = await super.find(ctx); // some more custom logic meta.date = Date.now() return { data, meta }; }, })); ``` -------------------------------- ### Install Project Dependencies and Build Source: https://docs-v4.strapi.io/llms-v4-full.txt Navigate to your project directory, install npm packages, and build your Strapi project. Uninstall sqlite3 if using PostgreSQL. ```bash cd ./my-project/ npm install NODE_ENV=production npm run build ``` -------------------------------- ### Create Strapi Project with Yarn Source: https://docs-v4.strapi.io/dev-docs/deployment/azure Use Yarn to create a new Strapi project without global package installations. This command initiates an interactive setup process. ```bash yarn create strapi-app mystrapiapp ``` -------------------------------- ### GET Request Collection Type with Axios in Next.js Source: https://docs-v4.strapi.io/llms-v4-full.txt Example of fetching all items from a 'restaurant' collection type using Axios in a Next.js application. Ensure 'find' permission is enabled. ```javascript const res = await axios.get('http://localhost:1337/api/restaurants'); ``` -------------------------------- ### Initialize a New Plugin Source: https://docs-v4.strapi.io/dev-docs/plugins/development/plugin-cli Use this command to create a new plugin in a specified directory. The path argument defines where the plugin will be created. ```bash strapi plugin:init ``` -------------------------------- ### GET Request with Fetch API Source: https://docs-v4.strapi.io/dev-docs/integrations/svelte Fetch restaurant data from the Strapi API using the browser's built-in Fetch API. This method does not require external package installation. ```javascript fetch('http://localhost:1337/api/restaurants', { method: 'GET', headers: { 'Content-Type': 'application/json', }, }) .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### Add HTTP Dependency to pubspec.yaml Source: https://docs-v4.strapi.io/dev-docs/integrations/flutter Include the http package in your Flutter project's pubspec.yaml file to enable HTTP requests. Run `flutter pub get` to install dependencies. ```yaml ... dependencies: flutter: sdk: flutter # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.0 http: ^0.12.2 ... ``` -------------------------------- ### Example v4 Controller (No Customization) Source: https://docs-v4.strapi.io/dev-docs/migration/v3-to-v4/code/controllers A complete example of a v4 controller file without any custom action overrides. It uses the `createCoreController` factory to define a basic controller. ```javascript const { createCoreController } = require('@strapi/strapi').factories; module.exports = createCoreController('api::api-name.content-type-name'); ``` -------------------------------- ### Setup PM2 Startup Script with User and Home Path Source: https://docs-v4.strapi.io/dev-docs/deployment/azure Execute the generated command to set up the PM2 startup script for systemd, specifying the user and home path. Replace 'your-name' with your actual username. ```bash sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u your-name --hp /home/your-name ``` -------------------------------- ### Specify Custom .env File Path Source: https://docs-v4.strapi.io/llms-v4-full.txt To use a .env file located elsewhere, set the ENV_PATH environment variable before starting the application. This example specifies an absolute path to the .env file. ```sh ENV_PATH=/absolute/path/to/.env npm run start ``` -------------------------------- ### Example v4 Service With Customization Source: https://docs-v4.strapi.io/dev-docs/migration/v3-to-v4/code/services This is a complete example of a v4 service file with customization. It demonstrates how to extend the `find` method to add a `counter` property to each result. ```javascript const { createCoreService } = require('@strapi/strapi').factories; module.exports = createCoreService('api::api-name.content-type-name', ({ strapi }) => ({ async find(...args) { const { results, pagination } = await super.find(...args); results.forEach(result => { result.counter = 1; }); return { results, pagination }; }, })); ``` -------------------------------- ### Make Strapi API Requests in Laravel Source: https://docs-v4.strapi.io/llms-v4-full.txt Invoke the custom Strapi macro to make authenticated requests to Strapi's GraphQL or REST API. Includes examples for POST and GET requests. ```php # Access to GraphQL $response = Http::strapi()->post('graphql', ['query' => $gqlQuery, 'variables' => $variables]); #Tip you might include a .gql file here using $gqlQuery = include('gqlQuery.gql') # Access to Api Rest $response = Http::strapi()->get('api/pages'); ``` -------------------------------- ### Initialize a new Strapi plugin with NPM Source: https://docs-v4.strapi.io/dev-docs/plugins/guides/use-the-plugin-cli Use this command to create a new Strapi plugin. Replace 'my-strapi-plugin' with your desired plugin name and path. ```bash npx @strapi/strapi plugin:init my-strapi-plugin ```