api.video

Learn how to integrate api.video with Strapi

api.video logo

Why Use api.video?

Ever find yourself needing a reliable, developer-friendly way to manage and deliver video content? Integrating api.video with Strapi could be just what you're looking for. By combining these two powerful platforms, you gain efficient streaming services, flexible integration options, and solid solutions for building interactive apps like live events and other Strapi real-time applications. The versatile video API integration simplifies uploading, processing, and controlling playback, enabling the creation of customized features. Plus, analytics reveal how viewers engage with your content, giving you insights to refine your strategy. And when your audience grows, scalability ensures performance doesn't take a hit.

For more details, check out the official documentation.

Why Use Strapi?

Strapi is the leading open-source headless CMS offering features, like customizable APIs, role-based permissions, multilingual support, etc. It simplifies content management and integrates effortlessly with modern frontend frameworks.

Explore the Strapi documentation for more details.

Strapi 5 Highlights

The out-of-the-box Strapi features allow you to get up and running in no time:

  1. Single types: Create one-off pages that have a unique content structure.
  2. Draft and Publish: Reduce the risk of publishing errors and streamline collaboration.
  3. 100% TypeScript Support: Enjoy type safety & easy maintainability
  4. Customizable API: With Strapi, you can just hop in your code editor and edit the code to fit your API to your needs.
  5. Integrations: Strapi supports integrations with Cloudinary, SendGrid, Algolia, and others.
  6. Editor interface: The editor allows you to pull in dynamic blocks of content.
  7. Authentication: Secure and authorize access to your API with JWT or providers.
  8. RBAC: Help maximize operational efficiency, reduce dev team support work, and safeguard against unauthorized access or configuration modifications.
  9. i18n: Manage content in multiple languages. Easily query the different locales through the API.
  10. Plugins: Customize and extend Strapi using plugins.

Learn more about Strapi 5 feature.

Setup Strapi 5 Headless CMS

We are going to start by setting up our Strapi 5 project with the following command:

šŸ–ļø Note: make sure that you have created a new directory for your project.

You can find the full documentation for Strapi 5 here.

Install Strapi

npx create-strapi-app@latest server

You will be asked to choose if you would like to use Strapi Cloud we will choose to skip for now.

 Strapi   v5.6.0 šŸš€ Let's create your new project

To deploy your project, create a new project on the Strapi Cloud dashboard.

? Please log in or sign up. 
  Login/Sign up 
āÆ Skip 

After that, you will be asked how you would like to set up your project. We will choose the following options:

? Do you want to use the default database (sqlite) ? Yes
? Start with an example structure & data? Yes <-- make sure you say yes 
? Start with Typescript? Yes
? Install dependencies with npm? Yes
? Initialize a git repository? Yes

Once everything is set up and all the dependencies are installed, you can start your Strapi server with the following command:

cd server
npm run develop

You will be greeted with the Admin Create Account screen.

003-strapi-5.png

Go ahead and create your first Strapi user. All of this is local so you can use whatever you want.

Once you have created your user, you will be redirected to the Strapi Dashboard screen.

004-strapi-5.png

Publish Article Entries

Since we created our app with the example data, you should be able to navigate to your Article collection and see the data that was created for us.

005-strapi-5.png

Now, let's make sure that all of the data is published. If not, you can select all items via the checkbox and then click the Publish button.

Strapi Articles Published

Enable API Access

Once all your articles are published, we will expose our Strapi API for the Articles Collection. This can be done in Settings -> Users & Permissions plugin -> Roles -> Public -> Article.

You should have find and findOne selected. If not, go ahead and select them.

007-strapi-5.png

Test API

Now, if we make a GET request to http://localhost:1337/api/articles, we should see the following data for our articles.

008-strapi-5.png

šŸ–ļø Note: The article covers (images) are not returned. This is because the REST API by default does not populate any relations, media fields, components, or dynamic zones.. Learn more about REST API: Population & Field Selection.

So, let's get the article covers by using the populate=* parameter: http://localhost:1337/api/articles?populate=*

vuejs strapi integration - api request.png

Getting Started with api.video

Let's dive into how to integrate api.video with Strapi, covering environment configuration and code implementation. If you're interested in more about video streaming with Strapi, this guide will help you start.

Installing and Adjusting Settings for api.video Integration

To connect api.video with your Strapi project, sign up for a free account at api.video. You'll get an API key for authentication.

To install the api.video SDK, use the following commands:

npm install @api.video/nodejs-client

or

yarn add @api.video/nodejs-client

Store your API key securely using environment variables: In your .env file, add:

API_VIDEO_KEY=your_unique_api_key

Load this variable within your Strapi configuration so it's available when needed.

Using api.video Uploader Strapi Plugin

Install api.video Strapi plugin:

yarn add @api.video/strapi-uploader-plugin@latest

After successful installation you've to re-build your Strapi instance. To archive that simply use:

yarn build
yarn develop

or just run Strapi in the development mode with watch option:

yarn develop watch

The api-video-uploader plugin should appear in the Plugins section of Strapi sidebar after you run app again.

As a next step you must configure your the plugin by the way you want to.

Code Implementation for Integrating api.video with Strapi

Here's how to integrate api.video within your Strapi environment:

  1. Set up a service for handling communications with api.video. In src/services/, create videoService.js:
    const ApiVideoClient = require('@api.video/nodejs-client');
    const { API_VIDEO_KEY } = process.env;
    
    const client = new ApiVideoClient({ apiKey: API_VIDEO_KEY });
    
    module.exports = {
      uploadVideo: async (filePath) => {
        try {
          const video = await client.videos.create({ title: 'Your Video Title' });
          const videoUploadStatus = await client.videos.upload(video.videoId, filePath);
          return videoUploadStatus;
        } catch (error) {
          console.error('Error uploading video:', error);
          throw error;
        }
      },
    };
  2. Add the video upload feature to your Strapi controllers. For example, api/video/controllers/video.js:
    module.exports = {
      async upload(ctx) {
        const file = ctx.request.files.video.path;
        try {
          // Implement your video upload logic here
          ctx.send({ message: 'Video uploaded successfully!' });
        } catch (error) {
          ctx.send({ error: 'Failed to upload video' });
        }
      },
    };

You're done, great job! (For more Strapi learning resources, check out the Strapi Video Library.)

Strapi Open Office Hours

If you have any questions about Strapi 5 or just would like to stop by and say hi, you can join us at Strapi's Discord Open Office Hours Monday through Friday at 12:30 pm - 1:30 pm CST: Strapi Discord Open Office Hours

For more details, visit the Strapi documentation and api.video documentation.

Frequently Asked Questions

api.video provides video hosting, encoding, and streaming services through a developer-friendly API. Integrate with Strapi to manage video content metadata while api.video handles the heavy lifting of video processing and delivery.

Create a custom upload provider or service that sends videos to api.video's upload endpoint. Store the returned video ID and embed information in Strapi content types for frontend access.

Yes, fetch video embed codes or player URLs from your Strapi content and render them using api.video's player SDK. The player handles adaptive streaming and playback controls.

api.video automatically transcodes uploads for adaptive streaming, generates thumbnails, and provides analytics. These features work automatically without additional Strapi configuration.

Store video titles, descriptions, and api.video IDs in Strapi content types. Manage the editorial content in Strapi while api.video handles video storage and delivery infrastructure.