Overview
Data API block allows developers to create REST, GraphQL, gRPC, and OData APIs without writing any code. Developers define the APIs required through YAML for 90% of the cases. If there are specific cases where more control is needed, they can extend the service with few lines of JavaScript or WASM.
Data API block does not generate any code. It creates required API endpoints at run-time based on the YAML files and configuration. Read more about our views on Model-Driven Development (MDD). This makes it faster to develop and easier to deploy.
Key Concepts
Datastore
Datastore is a logical grouping of enums, embeddables and entities. Every datastore is tied to a database.
Enums
Enums allow developers to define list of values. Entities can have one more fields with data type as enum.
1# enum for week days2enums:3- name: weekdays4 values:5 - value: Sunday6 - value: Monday7 - value: Tuesday8 - value: Wednesday9 - value: Thursday10 - value: Friday11 - value: Saturday
Embeddables
Embeddables are like entities, but do not have real tables or collection. They work like entities for validations and computed fields but cannot exist without entities. They are useful to create validated nested structures as JSON objects in relational table or as nested document in NoSQL collections.
1embeddables:2- name: pincode3 fields:4 - name: pincode5 type: string6 validations:7 - type: required
Traits
Traits are way to group together common features that entities should have, like common fields with validations. Developers apply traits to entities with the inherits
definition.
1namespace: kisai2traits:3- name: id4 fields:5 - name: id6 type: ulid7 defaultvalue: ulid()8 validations:9 - type: required10 - type: unique11 message: id field needs to be unique12 - type: final13 message: id field cannot be updated
Types
Data types are the categories of data values that can be stored, processed, and retrieved by a programming language. Common data types include numbers (integers, floats, complex), characters (single characters, strings), booleans (true/false), dates, times, and null/undefined values.
Having a universal type system allows for each integration between various services across technology stacks, programming language, and system boundaries.
Entities
Entities are foundational blocks of building datastores and APIs. Each entity is mapped to a table in a relation database and to a collection in a Document database.
1entities:2- name: ticket3 inherits: kisai.id4 fields:5 - name: name6 type: string7 validations:8 - type: required # validation marking the field as mandatory9 message: name is a required field # error message to send when validation fails10 - name: description11 type: string12 - name: duedate13 type: date14 - name: priority15 type: priority16 - name: state17 type: string18 stateflow: ticketflow
Stateflows
In kis.ai, we introduce a powerful feature called stateflows, which function similarly to state machines. Stateflows are assigned to fields within an application, defining the finite set of values a field can hold and the specific order in which these values can be transitioned.
1stateflows:2- name: ticketflow3 initial: Open4 states:5 - name: Open6 on:7 START:8 target: accepted9 - name: In Progress10 on:11 RESOLVE:12 target: Resolved13 - name: Resolved14 on:15 CLOSE:16 target: Closed17 REOPEN:18 target: Open19 - name: Closed20 type: final