BuildBot

Content and Search

Strapi content types

Lesson 1 of 5

What you'll learn

  • Distinguish collection types from single types
  • Read a content-type schema and its field definitions
  • See how an entry is validated against its fields

Strapi is a headless CMS: it stores structured content and exposes it over an API. Before any content exists, you define a content type — a schema that describes the shape of your data. Editors then fill in entries that must match that shape.

There are two kinds. A collection type holds many entries of the same shape (Articles, Products, Authors). A single type holds exactly one entry (Homepage, Site Settings).

{
  "kind": "collectionType",
  "collectionName": "articles",
  "info": { "singularName": "article", "pluralName": "articles" },
  "attributes": {
    "title":   { "type": "string", "required": true },
    "body":    { "type": "richtext" },
    "views":   { "type": "integer", "default": 0 },
    "author":  { "type": "relation", "relation": "manyToOne", "target": "api::author.author" }
  }
}

The schema is a contract

Each field in attributes declares a type (string, integer, boolean, richtext, relation, ...) and optional rules like required or default. When an editor saves an entry, Strapi checks it against this contract: required fields must be present, and values must match the declared type. A schema is the single source of truth — change it, and the API, database, and admin UI all follow.

Schema lives in code

A content type's schema is stored as a schema.json file in your project, not just in the database. That means your content model is versioned in git alongside the rest of your app.

The challenge below models that validation step: given a schema and a candidate entry, check that required fields exist and that types line up.

Validate an entry against a schema

Run it. The validator walks each field in the schema and reports any missing required fields or type mismatches in the entry.

Loading editor…

Next: how Strapi turns this schema into a ready-made API.

Sign in to save your progress across devices.