Docs
Get Started

Get Started

This Getting Started Guide is designed to help you get started using Collections to manage your content.

1. Create a project

The easiest way to get started with Collections is to use the create-collections-app package.

npx create-collections-app my-app

Collections supports multiple databases. Each database has different configuration options, but don't worry. Simply answer the installer's questions to complete the setup.

// Choose your database client
? Which one? SQLite is the simplest. (Use arrow keys)
❯ SQLite
  MySQL / MariaDB
  PostgreSQL

In SQLite

// Enter the path to the database file
? Database File Path: (/my-app/data.db)

In MySQL / MariaDB

// Enter your database host
? Database Host: (127.0.0.1)
 
// Please enter the database port
? Port: (3306)
 
// Enter the database name
? Database Name: (collections)
 
// Enter the database user
? Database User:
 
// Enter the database password
? Enter the database password:

In PostgreSQL

// Enter your database host
? Database Host: (127.0.0.1)
 
// Please enter the database port
? Port: (5432)
 
// Enter the database name
? Database Name: (collections)
 
// Enter the database user
? Database User:
 
// Enter the database password
? Enter the database password:
 
// Enable SSL
? Enable SSL: (y/N)

Next, create the administrator user.

// Enter your email address
? Email: (admin@example.com)
 
// Please enter a password
? Password

Setup is now complete! Let's start the application by executing the following command.

cd my-app
npm run dev

Open http://localhost:4000/admin (opens in a new tab) and you should see your app running.

2. Create a data model

Once logged in, you will see an options screen to create your first data model.

  1. Navigate to the data model.
  2. Enter a name.
    • The name of the data model this time is posts.
  3. Save the data model.
  4. After successful saving, posts will appear in the content management of the menu bar.

Learn More About Data model

3. Add fields

Once you have created your first data model, it is time to add fields. To start, try creating the most common text fields.

  1. Navigate to Configuration > Data Model > posts.
  2. Click on Add Field.
  3. Select the field type.
  4. Enter a field name and label.
    • For our purposes, we will use title as the field name.
  5. Save the file.

4. Create content

Now that the data model and fields are ready, let's create the content.

  1. Navigate to Content Management > posts.
  2. Click on New Registration.
  3. Enter a value for title.
  4. Save the content.

5. Set roles and permissions

Collections has two built-in roles: General and Admin. General roles are provided with all permissions turned off and can be added as needed. The Administrator role has all permissions and cannot be changed.

All content registered in Collections is considered private. Therefore, permissions must be granted to access them. So let's add read permission so that the API returns our content.

  1. Navigate to Configuration > Roles.
  2. Click on New Registration
  3. Enter a role name
    • This time, the role name will be public and leave admin permissions off.
  4. Save the role.
  5. On the role edit screen, change the read permission for posts to Change to allow.

6. Connect to the API

Now that we have content to publish to the project, it is time to start using this content externally! Collections supports accessing it via a REST API endpoint. Collections supports access via REST API endpoints. For this example, let's use the preview function as the easiest way to access the API.

  1. Navigate to Content Management > posts.
  2. Click on.
  3. Click "Get" on the preview screen that appears.
    • If your API key is not yet registered, click the link to create an API key on your profile screen.

Then there you have your posts content, served up in beautiful JSON, ready to be used anywhere!

{
	"data": [
		{
			"id": 1,
			"createdAt": "2023-10-03T00:34:56.486Z",
			"updatedAt": "2023-10-03T00:34:56.486Z",
			"title": "Hello World"
		}
	]
}

In this example, we used the API to make a very simple read request, but there is more. Collections provides exhaustive endpoints such as registration, update, and deletion, and all actions your app can perform can be done via the API.