Skip to content

Strapi

Overview

Strapi is an open-source headless CMS that gives developers the freedom to choose their favorite tools and frameworks and allows editors to manage and distribute their content using their application’s admin panel. Based on a plugin system, its admin panel and API are extensible. Every part is customizable to match any use case. Strapi also has a built-in user system to manage what the administrators and end users can access.

Prerequisites

Installation and Setup

Follow the steps below to setup Strapi locally.

  1. First, install Strapi locally:

    npx create-strapi-app my-project
    
    You can view your Strapi project as it is hosted locally at http://localhost:1337/admin.

  2. Install the Strapi hook:

    npm i strapi-hook-astra
    

  3. Activate the hook by adding the following to ./config/hook.js of the sample Strapi Project:

    module.exports = {
        settings: {
            astra: {
                enabled: true,
                token: 'REPLACE_ME',
                databaseId: 'REPLACE_ME',
                databaseRegion: 'REPLACE_ME',
                keyspace: 'REPLACE_ME',
                collection: 'REPLACE_ME'
            },
        }
    };
    
    Where:

  4. token: Generate a token from Astra DB.
  5. databaseId: Enter your Astra DB database ID from your database URL.
  6. databaseRegion: Enter your Astra DB database region
  7. keyspace: Enter your Astra DB keyspace name.
  8. collection: Enter your Astra DB collection name.

Test and Validate

  1. Create a document:

    strapi.services.astra.create(document);
    
    |Parameter|Type|Explanation|Values| |:---|:---|:---|:---| |document|json|Create a document|var dataString = '{ "name": "John", "last_name": "Doe" }'|

  2. Get document by ID:

    strapi.services.astra.getById(documentId);
    
    |Parameter|Type|Explanation|Values| |:---|:---|:---|:---| |documentId|string|Get document by documentId|var documentId = "your_document_id"|

  3. Get document by path:

    strapi.services.astra.getByPath();
    

  4. Search a collection:

    strapi.services.astra.searchCollection(query,pagesize);
    
    |Parameter|Type|Explanation|Values| |:---|:---|:---|:---| |query|string|Search collection via query|var query = {"name": { "$eq": "John" }}| |pagesize|int|Number of documents to fetch|int page_size = 3|

For more, see the Strapi documentation.


Last update: 2023-10-13