### File Dependencies Example
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/MANIFEST.md
Illustrates the dependency structure of the documentation files, starting from the README.md entry point.
```markdown
README.md (entry point)
├── module-configuration.md
├── composables-core.md
├── composables-auth.md
├── composables-graphql.md
├── api-v5.md
├── api-v4.md
├── api-v3.md
├── types.md
├── errors.md
├── utilities.md
├── quick-reference.md (summary)
└── api-index.md (index)
```
--------------------------------
### Complete Authentication Example (Vue)
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/composables-auth.md
A full Vue component example demonstrating login, logout, and user state management using Nuxt Strapi authentication composables.
```vue
Welcome, {{ user.username }}!
```
--------------------------------
### Fetch Articles using useStrapi Client
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/README.md
Fetch a list of articles using the auto-imported `useStrapi` composable. This example demonstrates fetching data in a Vue component's setup script.
```vue
{{ item.title }}
```
--------------------------------
### Strapi Pagination Examples
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/quick-reference.md
Examples of pagination parameters for Strapi v4/v5, including by page, by offset, and the structure of the response metadata.
```json
// By page (v4/v5)
{ pagination: { page: 2, pageSize: 20 } }
// By offset (v4/v5)
{ pagination: { start: 20, limit: 20 } }
// Response metadata (v4/v5)
response.meta.pagination = {
page: 2,
pageSize: 20,
pageCount: 5,
total: 100
}
```
--------------------------------
### stringify Example: Manual Usage
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/utilities.md
Provides an example of using the `stringify` function directly to construct a full API URL with query parameters.
```typescript
import { stringify } from '~/src/runtime/utils/stringify'
const queryString = stringify({
filters: { status: 'active' },
sort: 'createdAt:desc'
})
const fullUrl = `https://api.example.com/articles?${queryString}`
```
--------------------------------
### Strapi Sorting Examples
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/quick-reference.md
Examples for sorting query results in Strapi, including single and multiple fields, and the v3 specific format.
```json
// Single field
{ sort: 'createdAt:desc' }
{ sort: 'title:asc' }
// Multiple fields
{ sort: ['category:asc', 'title:asc'] }
// v3 format
{ _sort: 'createdAt:DESC' }
{ _sort: ['category:ASC', 'createdAt:DESC'] }
```
--------------------------------
### Install Nuxt Strapi Module
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/README.md
Install the module using npm. This is the first step to integrate Strapi with your Nuxt application.
```bash
npm install @nuxtjs/strapi
```
--------------------------------
### Example: Basic Create
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/api-v5.md
Demonstrates a basic creation of an article with title, content, and slug.
```typescript
const client = useStrapi()
// Basic create
const newArticle = await client.create('articles', {
title: 'My Article',
content: 'Article content',
slug: 'my-article'
})
console.log(newArticle.data.documentId)
```
--------------------------------
### Fetch User Data with Variables in Script Setup
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/composables-graphql.md
Demonstrates fetching user data using `useStrapiGraphQL` with dynamic variables in a script setup context. Uses a computed property for the query and defines an async function to execute it.
```vue
```
--------------------------------
### Install Preview Release of Nuxt Strapi
Source: https://github.com/nuxt-modules/strapi/blob/main/docs/content/2.setup.md
Install a continuous preview release of the `@nuxtjs/strapi` module by specifying a URL pointing to a specific commit hash or PR number on pkg.pr.new.
```diff
{ "dependencies": {
- "@nuxtjs/strapi": "^2.1.1",
+ "@nuxtjs/strapi": "https://pkg.pr.new/@nuxtjs/strapi@95260d0",
}
}
```
--------------------------------
### Complete Nuxt Strapi Integration Example
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/composables-core.md
A full Vue component example demonstrating the integration of various Nuxt Strapi composables like `useStrapiUser`, `useStrapiUrl`, `useStrapiVersion`, `useStrapiClient`, and `useStrapiMedia` for fetching and displaying data.
```vue
Dashboard
Welcome, {{ user.username }}
API Version: {{ version }}
API Base URL: {{ apiUrl }}
```
--------------------------------
### Example: Create with Relations
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/api-v5.md
Shows how to create an article and associate it with existing author and category entries using their IDs.
```typescript
const client = useStrapi()
// Create with relations
const withRelations = await client.create('articles', {
title: 'Article with Author',
content: 'Content',
author: 1, // Author ID
category: 3 // Category ID
})
```
--------------------------------
### Example: Create with Locale
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/api-v5.md
Illustrates creating an article in a specific locale, such as French.
```typescript
const client = useStrapi()
// Create with locale
const frenchArticle = await client.create('articles', {
title: 'Mon Article',
content: 'Contenu'
}, {
locale: 'fr'
})
```
--------------------------------
### Make Authenticated Strapi Requests
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/composables-core.md
Demonstrates making GET, POST, and filtered GET requests using the Strapi client. Ensure the client is initialized before use. Handles typed responses and request options.
```typescript
const client = useStrapiClient()
// GET request
const articles = await client('/articles')
// POST request
const newArticle = await client('/articles', {
method: 'POST',
body: {
data: {
title: 'New Article',
content: 'Content here'
}
}
})
// Request with query parameters
const filtered = await client('/articles', {
method: 'GET',
params: {
fields: ['title', 'slug'],
filters: {
published: true
},
sort: 'createdAt:desc'
}
})
```
--------------------------------
### stringify Example: Simple Object
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/utilities.md
Demonstrates the basic usage of the `stringify` function with a simple key-value object.
```typescript
import { stringify } from '~/src/runtime/utils/stringify'
// Simple object
stringify({ name: 'John', age: 30 })
// Returns: "name=John&age=30"
```
--------------------------------
### stringify Example: HTTP Client Parameters
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/utilities.md
Shows the transformation of a `params` object into a URL query string when using `useStrapiClient`.
```typescript
const client = useStrapiClient()
// Before: params object
await client('/articles', {
params: {
filters: { published: true }
}
})
// After stringify:
// GET /api/articles?filters[published]=true
```
--------------------------------
### Example: Update with Locale
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/api-v5.md
Updates an article in a specific locale, such as French.
```typescript
const client = useStrapi()
// With locale
const translated = await client.update('articles', 'doc123', {
title: 'Titre Français'
}, {
locale: 'fr'
})
```
--------------------------------
### stringify Example: Array Handling
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/utilities.md
Demonstrates how `stringify` expands arrays with indexed keys and handles nested array objects.
```typescript
stringify({
tags: ['a', 'b', 'c']
})
// Returns: "tags[0]=a&tags[1]=b&tags[2]=c"
// For nested array objects
stringify({
items: [
{ id: 1 },
{ id: 2 }
]
})
// Returns: "items[0][id]=1&items[1][id]=2"
```
--------------------------------
### Complete CRUD Example for Articles
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/api-v5.md
Demonstrates full Create, Read, Update, and Delete operations for 'articles' using the Nuxt Strapi module client. Includes local state management for articles and editing.
```vue
Create Article
Articles
{{ article.title }}
{{ article.content }}
```
--------------------------------
### Strapi Population Examples
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/quick-reference.md
Demonstrates how to populate related data in Strapi queries, including simple field population and deep population with filtering and sorting for nested relations.
```json
// Simple populate
{ populate: ['author', 'category'] }
{ populate: 'author' }
{ populate: '*' } // All relations
// Deep population (v4/v5)
{
populate: {
author: {
fields: ['name', 'email'],
populate: ['avatar']
},
comments: {
sort: 'createdAt:desc',
pagination: { limit: 5 }
}
}
}
```
--------------------------------
### Strapi Filter Examples
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/quick-reference.md
Examples of various filter operators for querying Strapi data, including equality, case-insensitivity, contains, numeric comparisons, array membership, NULL checks, and logical operators.
```json
// Equality
{ title: { $eq: 'Test' } }
// Case-insensitive
{ title: { $eqi: 'test' } }
// Contains
{ title: { $contains: 'str' } }
// Case-insensitive contains
{ title: { $containsi: 'STR' } }
// Starts with
{ title: { $startsWith: 'Test' } }
// Numeric comparison
{ views: { $gte: 100 } }
{ views: { $between: [10, 100] } }
// Array membership
{ status: { $in: ['published', 'draft'] } }
// NULL checks
{ author: { $notNull: true } }
// Logical operators
{ $or: [{ published: true }, { featured: true }] }
{ $and: [{ views: { $gte: 100 } }, { published: true }] }
```
--------------------------------
### stringify Example: Single Value
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/utilities.md
Illustrates the output of `stringify` for a simple object with a single key-value pair.
```typescript
stringify({ name: 'test' })
// Returns: "name=test"
```
--------------------------------
### stringify Example: Strapi v3 Compatibility
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/utilities.md
Demonstrates how `stringify` produces query strings compatible with Strapi v3's underscore-prefixed parameters like `_where` and `_sort`.
```typescript
stringify({
_where: { published: true },
_sort: 'createdAt:DESC',
_limit: 10
})
// Returns: "_where[published]=true&_sort=createdAt%3ADESC&_limit=10"
```
--------------------------------
### stringify Example: Empty Object
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/utilities.md
Shows the output of `stringify` when an empty object is provided as input.
```typescript
stringify({})
// Returns: ""
```
--------------------------------
### stringify Example: Array Values
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/utilities.md
Illustrates `stringify`'s ability to handle arrays by converting them into indexed bracket notation.
```typescript
import { stringify } from '~/src/runtime/utils/stringify'
// Array values
stringify({
tags: ['nuxt', 'strapi']
})
// Returns: "tags[0]=nuxt&tags[1]=strapi"
```
--------------------------------
### stringify Example: Nested Object
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/utilities.md
Shows how `stringify` handles nested objects by converting them into bracket notation for query parameters.
```typescript
import { stringify } from '~/src/runtime/utils/stringify'
// Nested object
stringify({
filters: {
published: true,
category: 'tech'
}
})
// Returns: "filters[published]=true&filters[category]=tech"
```
--------------------------------
### Create a New Restaurant
Source: https://github.com/nuxt-modules/strapi/blob/main/docs/content/3.usage.md
Creates a new restaurant document using the `create` method from the `useStrapi` composable. The `name` property is provided as an example of data to be created.
```vue
```
--------------------------------
### Fetch Paginated and Sorted Articles
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/README.md
Fetch a list of articles with specific pagination and sorting parameters. This example uses the `find` method with options for pagination and sorting.
```typescript
const client = useStrapi()
const response = await client.find('articles', {
pagination: { page: 1, pageSize: 10 },
sort: 'createdAt:desc'
})
```
--------------------------------
### Handle Login Failures
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/errors.md
Manage authentication errors during the login process. This example checks for specific error statuses like 400 (invalid credentials) and 401 (user not confirmed).
```typescript
const { login } = useStrapiAuth()
try {
const response = await login({
identifier: 'user@example.com',
password: 'wrong'
})
} catch (error) {
const e = error as Strapi5Error
if (e.error.status === 400) {
// Invalid credentials
console.error('Email or password incorrect')
} else if (e.error.status === 401) {
// User not confirmed
console.error('Account not confirmed')
}
}
```
--------------------------------
### GraphQL Mutation Example with useStrapiGraphQL
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/composables-graphql.md
Shows how to execute a GraphQL mutation (e.g., creating an article) using the useStrapiGraphQL composable. Mutations require an input object and return data based on the mutation definition.
```typescript
const strapiGraphQL = useStrapiGraphQL()
interface CreateArticleResponse {
createArticle: {
id: string
title: string
}
}
const response = await strapiGraphQL(
`
mutation CreateArticle($input: ArticleInput!) {
createArticle(input: $input) {
id
title
}
}
`,
{
input: {
title: 'New Article',
content: 'Article content here',
published: true
}
}
)
console.log('Created article ID:', response.createArticle.id)
```
--------------------------------
### Strapi Locale Examples
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/quick-reference.md
Specify the desired locale for fetching localized content in Strapi. v5 allows `null` to fetch the default locale.
```json
{ locale: 'fr' }
{ locale: 'en-US' }
{ locale: 'de-DE' }
// v5 allows null for default
{ locale: null }
```
--------------------------------
### Type-Safe Filtering Example
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/types.md
Demonstrates how to perform type-safe filtering on articles using various operators. Ensure the Article type is defined and the Strapi client is initialized.
```typescript
interface Article {
title: string
content: string
views: number
published: boolean
}
const client = useStrapi()
// Type-safe filters
const filtered = await client.find('articles', {
filters: {
// String operators
title: { $contains: 'Strapi' },
// Numeric operators
views: { $gte: 100 },
// Logical operators
$or: [
{ published: { $eq: true } },
{ views: { $gt: 1000 } }
]
}
})
```
--------------------------------
### stringify Example: Internal Recursion Detail
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/utilities.md
Explains the internal mechanism of `stringify` using the `prefix` parameter for handling nested object keys during recursion.
```typescript
// First call: stringify(obj, undefined)
stringify({
filters: {
published: true
}
})
// Internally becomes:
// stringify({ published: true }, 'filters')
// Which produces: "filters[published]=true"
```
--------------------------------
### Example: Standard Update
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/api-v5.md
Performs a standard update on an article, modifying its title and setting the published date.
```typescript
const client = useStrapi()
// Standard update
const updated = await client.update('articles', 'doc123', {
title: 'New Title',
publishedAt: new Date().toISOString()
})
```
--------------------------------
### Install and Configure Nuxt Strapi Module
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/quick-reference.md
Add the Nuxt Strapi module to your nuxt.config.ts and configure the Strapi API URL and version.
```typescript
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@nuxtjs/strapi'],
strapi: {
url: 'http://localhost:1337',
version: 'v5' // or 'v4', 'v3'
}
})
```
--------------------------------
### stringify Example: Integration with useStrapiClient
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/utilities.md
Illustrates how `useStrapiClient` internally uses `stringify` to convert a params object into a URL query string for API requests.
```typescript
const client = useStrapiClient()
const params = {
fields: ['title', 'slug'],
filters: { published: true },
pagination: { page: 1, pageSize: 10 }
}
// Internally, these params are stringified:
const url = '/articles?' + stringify(params)
// Result: "/articles?fields[0]=title&fields[1]=slug&filters[published]=true&pagination[page]=1&pagination[pageSize]=10"
await client('/articles', { params })
```
--------------------------------
### useStrapiMedia
Source: https://github.com/nuxt-modules/strapi/blob/main/_autodocs/composables-core.md
Constructs absolute URLs for media files from Strapi. It takes a relative path or a full URL and returns an absolute URL ready for use in HTML elements like `` or `