Skip to main content

Entity Object

Introduction#

Entity object is the main resource of Architect. You can easily construct new entities by sending out POST request to the defined route specifying the name of the entity in plural.

If the entity that you want to store inside the database is a todo for example, the route pointing to the collection of all todos would be /api/todos. This way Architect knows that it should store that in a specific table created at the time of first use.

note

Entity is a single resource stored inside the database

note

Collection is a set of entities that will be manipulated through the API. Ex todos or cars

Anatomy of the Entity Object#

Due to flexible nature of Architect, Entity Object can be anything you imagine. After you create your entity by passing in a JSON via POST request, Architect will return a unique ID for that resource alongside with utility fields like created_at and updated_at.

If we would define our POST request like this:

/src/service/todos/create.js
const createTodo = (title: string) => {
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
const raw = JSON.stringify({ title: title });
const requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
};
fetch("https://your_app_id.essentialz.cloud/api/todos", requestOptions)
.then(response => response.json())
.then(result => console.log(result))
.catch(error => console.log('error', error));
}

And call that createTodo method with Get come milk passed to it.

createTodo("Get some milk");

This would be the response generated for us By Architect.

{
"id": "1bd666ce-c495-4bae-8664-5148f2be5462",
"created_at": "1619453858.1403806",
"updated_at": "1621962533.5391407",
"title": "Get some milk"
}