Skip to content

Start

Create your first content type

This tutorial grows the post content type from the Quickstart into a small blog. You add an author content type, link each post to its author, turn on drafts and publishing, and read a post back with its author in one call. Along the way you preview a change before you apply it, the way you would on a live site.

You describe the shape of the content and the engine creates the storage for it in your database. You never write SQL or a migration file, and the same definition works on PostgreSQL, MySQL and SQL Server.

  • You did step 4 of the Quickstart, or you start here: applying the definition in step 4 below creates post when it does not exist yet.
  • Changing content types takes the admin or super_admin role. Writing entries also works as an editor.
  • For the console steps, you are signed in to LyEve Console. Its Schema builder edits each content type in a list. With Schema Pro the same editor also opens from a visual canvas of every content type.
  • For the API steps, TOKEN holds a token for an admin or super_admin account. Steps 2 and 3 of the Quickstart get one. The commands run from one directory, because step 2 saves a file there.

Console v0.28.0

  1. Open Schema builder and choose New schema.
  2. Enter Author in Display name and author in Machine name.
  3. Choose Add field, name it name, keep the type text and tick Req.
  4. Choose Add field, name it bio and keep the type text.
  5. Choose Save.

Engine API v0.62.0

Shell
curl -X POST http://localhost:3001/api/admin/schemas \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "author",
"display_name": "Author",
"fields": [
{ "name": "name", "field_type": "text", "required": true },
{ "name": "bio", "field_type": "text" }
]
}'

The answer is 200 with the stored definition.

The display name is the label the console shows. A required name refuses an author with no name.

The new Post keeps the Quickstart's two fields and adds two:

What is newWhat it does
slug, indexedFinding a post by its slug stays fast as the blog grows
authorA belongs_to relation: each post points at one entry of author

Console v0.28.0

  1. In Schema builder, choose Post in the list of content types.
  2. Choose Add field, name it slug, keep the type text and tick Idx.
  3. Choose Add relation and name the field author. Under Relation, keep Belongs to one, and pick Author in Target schema.

The schema builder with the Post content type open: its display name, machine name and fields with their types, and the relation panel of the author field.

Engine API v0.62.0

Save this as post-schema.json:

JSON
{
"name": "post",
"display_name": "Post",
"with_draft_publish": true,
"fields": [
{ "name": "title", "field_type": "text", "required": true },
{ "name": "body", "field_type": "rich_text" },
{ "name": "slug", "field_type": "text", "indexed": true },
{ "name": "author", "field_type": "relation", "relation_type": "belongs_to", "relation_to": "author" }
]
}

with_draft_publish also turns on drafts and publishing, which step 5 explains.

The data model lists every field type, every flag such as unique and default, the validation rules and the other kinds of relation.

Ask what the new definition would change before you apply it.

Console v0.28.0

Choose Preview DDL. Each statement shows the SQL a save would run, and Down SQL shows the SQL that undoes it. Choose Close when you have read them.

Engine API v0.62.0

Shell
curl -X POST http://localhost:3001/api/admin/schemas/post/preview-ddl \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d @post-schema.json

The answer is {"statements": [...]}, each with a description, the sql an apply would run and the down_sql that undoes it. The file also turns on drafts, so the API's preview adds a status column.

For this change you see a column for slug and its index, and for the author a column, a step that clears links to authors that do not exist, a foreign key and an index. Nothing changes until you apply.

Console v0.28.0

Choose Save. The badge beside the name reads Saved. The Post has no drafts yet, and step 5 turns them on.

Engine API v0.62.0

Shell
curl -X POST http://localhost:3001/api/admin/schemas \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d @post-schema.json

The answer is 200 with the definition as stored. The Quickstart's first post, written before drafts were on, is now published. Applying the same file again changes nothing.

The engine compares the new definition with the stored one and changes only what differs. Existing entries keep their values.

Removing a field later does not delete its data right away. The removal waits until a super admin applies it, so a mistaken edit loses nothing. The data model covers renames and removals.

With drafts on, each post carries a status: draft, published or archived. Only the API turns drafts on: the schema builder in console v0.25.0 has no switch for them. If you followed the API steps, post-schema.json turned them on in step 4, so go on to step 6.

From the console path, run two commands. They use the address of Run the engine and the console together. An engine on its own takes the same calls on port 3001. Sign in with your console account and keep the token:

Shell
curl -X POST http://localhost:8080/api/admin/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "you@example.com", "password": "<your password>"}'
export TOKEN="<the token from the answer>"

Then save Post again with drafts turned on:

Shell
curl -X POST http://localhost:8080/api/admin/schemas \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "post",
"display_name": "Post",
"with_draft_publish": true,
"fields": [
{ "name": "title", "field_type": "text", "required": true },
{ "name": "body", "field_type": "rich_text" },
{ "name": "slug", "field_type": "text", "indexed": true },
{ "name": "author", "field_type": "relation", "relation_type": "belongs_to", "relation_to": "author" }
]
}'

The answer is 200 with "with_draft_publish": true.

Console v0.28.0

  1. Open Content, choose Author and then New entry.
  2. Enter Ada Lovelace in Name and Writes about engines. in Bio, then choose Create.
  3. Open Content > Post and choose New entry.
  4. Enter a Title, a Slug such as notes-on-the-engine and some text in Body.
  5. In Author, type part of the name and pick Ada Lovelace.
  6. Choose Create.

A post created in the console starts as a draft. Open it and choose Publish to publish it.

Engine API v0.62.0

Create the author:

Shell
curl -X POST http://localhost:3002/api/v1/content/author \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"data": {"name": "Ada Lovelace", "bio": "Writes about engines."}}'

The answer is 201 with the new entry. Copy its id:

Shell
export AUTHOR_ID="<the id from the answer>"

Create a post that points at the author. A belongs_to field takes the other entry's id:

Shell
curl -X POST http://localhost:3002/api/v1/content/post \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"data": {
"title": "Notes on the engine",
"slug": "notes-on-the-engine",
"body": "<p>A first look.</p>",
"author": "'"$AUTHOR_ID"'"
}
}'
Shell
export POST_ID="<the id from the answer>"

The answer carries the link as author_id under data, and _status is published. A post created through the Content API takes the _status its data names, such as "_status": "draft", and is published when it names none.

7. Take it back to draft, then publish it

Link to the section 7. Take it back to draft, then publish it

Console v0.28.0

  1. Open the post from Content > Post and choose Unpublish. Its status in the list reads draft.
  2. The Draft and Published filters above the list show the entries in each status.
  3. Open the post again and choose Publish.

Engine API v0.62.0

Shell
curl -X PUT http://localhost:3002/api/v1/content/post/$POST_ID/unpublish \
-H "Authorization: Bearer $TOKEN"

The answer is 204 with no body. The post is a draft now, so a plain list leaves it out: GET /api/v1/content/post returns published entries only. To see the drafts, filter on the status. The -g flag stops curl from reading the square brackets as a pattern:

Shell
curl -g "http://localhost:3002/api/v1/content/post?filters[_status]=draft" \
-H "Authorization: Bearer $TOKEN"

Publish it again:

Shell
curl -X PUT http://localhost:3002/api/v1/content/post/$POST_ID/publish \
-H "Authorization: Bearer $TOKEN"

The answer is 204, and the post is back in the list.

Reading a post together with its author is a Content API call, the one a site or an app makes. The console shows the author's name in the Author column of the Post list instead.

Find the post by its slug, and ask for the author to come with it:

Shell
curl -g "http://localhost:3002/api/v1/content/post?filters[slug]=notes-on-the-engine&populate=author" \
-H "Authorization: Bearer $TOKEN"
JSON
[
{
"id": "4769807e-2cbe-487b-be6f-1c87aabfbaa3",
"data": {
"title": "Notes on the engine",
"slug": "notes-on-the-engine",
"body": "<p>A first look.</p>",
"_status": "published",
"author_id": "6c5b5d81-fa95-448d-ab1f-385bfad85209",
"author": {
"id": "6c5b5d81-fa95-448d-ab1f-385bfad85209",
"name": "Ada Lovelace",
"bio": "Writes about engines.",
"created_at": "2026-10-02T05:06:55.656177Z",
"updated_at": "2026-10-02T05:06:55.656177Z"
}
},
"created_at": "2026-10-02T05:06:55.693943Z",
"updated_at": "2026-10-02T05:07:03.696363Z"
}
]

GET /api/v1/content/post/$POST_ID reads one post by its id, and takes populate too. Your account may read drafts, so a draft comes back as well. A caller who may not read drafts gets 404 for one.

  • Drafts and publishing: how editors work with drafts, revisions and scheduled publishing in the console.
  • Content history: turn on revisions for the content types that need them.
  • Schema changes: presets, renames and the history of every change.
  • Webhooks: tell another system when a post is published.
  • API endpoints: paging, cursors and every other route that reads and writes entries.