Building a NextJS Sample App with Kontent.ai

May 01, 2024

Next.js and Kontent.ai

In this blog post, we will walk through the process of building a sample application using Next.js and Kontent.ai. We will be using the ‘Create multi-brand project’ feature in Kontent.ai to manage content for multiple brands in a single project.

Introduction

Next.js is a popular React framework that enables developers to build server-side rendering and static web applications. It’s known for its performance, scalability, and ease of use. On the other hand, Kontent.ai is a headless CMS that allows you to manage your content in one place and deliver it via APIs. The ‘Create multi-brand project’ feature allows you to manage content for multiple brands in a single project, making it easier to maintain consistency and efficiency.

Setting Up Your Development Environment

Before we start, make sure you have the following installed on your system:

  • Node.js and npm
  • Git
  • A code editor like Visual Studio Code

Creating a New Next.js App

First, let’s create a new Next.js application. Open your terminal and run the following command:

npx create-next-app@latest my-app

This command will create a new Next.js application in a directory called my-app.

Setting Up Kontent.ai

Next, we need to set up Kontent.ai. If you don’t have an account yet, you can sign up for a free one on their website. Once you’re logged in, create a new project using the ‘Create multi-brand project’ feature.

Integrating Kontent.ai with Next.js

Now that we have our Next.js app and Kontent.ai project set up, it’s time to integrate the two. We’ll use the @kentico/kontent-delivery package to fetch content from Kontent.ai and display it in our Next.js app.

Install the package by running:

npm install @kentico/kontent-delivery

Fetching Content from Kontent.ai

With the @kentico/kontent-delivery package installed, we can now fetch content from Kontent.ai. Here’s a sample code snippet on how you can do this:

import { DeliveryClient } from '@kentico/kontent-delivery';

const client = new DeliveryClient({ projectId: 'YOUR_PROJECT_ID' });

client.items()
  .type('article')
  .toPromise()
  .then(response => console.log(response.items));

Conclusion

And that’s it! You’ve just built a sample Next.js application with Kontent.ai using the ‘Create multi-brand project’ feature. This is just the beginning, and there’s a lot more you can do with these powerful tools. Happy coding!

Please note that this is a basic draft and you might need to add more details based on your specific use case or audience. Let me know if you need help with anything else. Happy blogging! 😊

Related Links: