Skip to main content
Prerequisites:
  • Nuxt 3.0 or higher
  • TypeScript enabled in your Nuxt project
  • Strapi v4 or v5 backend
Strapi2Front generates TypeScript types, services, and Zod schemas for your Nuxt applications. Server Routes generation is coming soon.

Current Support

TypeScript Types

Fully typed interfaces for all content types

Service Functions

Ready-to-use data fetching functions

Zod Schemas

Validation schemas for forms and mutations

Server Routes

Coming soon in a future release

Setup

1

Install Strapi2Front

Install the package in your Nuxt project:
2

Initialize Configuration

Run the init command to create a configuration file:
3

Configure for Nuxt

Update your strapi2front.config.ts:
strapi2front.config.ts
4

Add Environment Variables

Create a .env file:
.env
5

Generate Code

Run the sync command:
This generates:

Usage

Server-Side Rendering

Fetch data in your pages using useAsyncData or useFetch:

Client-Side Fetching

Fetch data on the client with reactivity:
components/ArticleList.vue

Server API Routes

Create API routes using the generated services:

Composables

Create reusable composables for common data fetching patterns:
composables/useArticles.ts
Use the composable in your components:
pages/blog.vue

Form Handling

Validate forms with Zod schemas:
components/ContactForm.vue

Service Functions Reference

All generated services include these methods:

Collection Types

Fetch multiple items with pagination:

Advanced Patterns

Static Site Generation

Pre-render pages at build time:
pages/blog/[slug].vue
Configure nuxt.config.ts for SSG:
nuxt.config.ts

Data Caching

Cache data with cachedFunction:
server/utils/cache.ts

Parallel Requests

Fetch multiple resources in parallel:

Server Routes (Coming Soon)

Server Routes generation for Nuxt is in development and will be available in a future release.
When available, server routes will be automatically generated:

Best Practices

Use useAsyncData or useFetch for SSR data fetching to benefit from automatic hydration.
Keep your STRAPI_API_TOKEN secure and only use it in server-side code (API routes, server middleware).
Create composables for common data fetching patterns to keep your code DRY.
Use watch in useAsyncData to automatically refetch when dependencies change.

Troubleshooting

Hydration Mismatch

Ensure you’re using useAsyncData or useFetch for SSR data fetching.

Type Errors

Regenerate types after schema changes:

CORS Issues

Configure CORS in your Strapi backend to allow requests from your Nuxt domain.

Next Steps

Services

Learn about service functions

Schemas

Use Zod schemas for validation

Relations

Work with Strapi relations

Types

Understand TypeScript types