Rust API reference
App
The App
struct represents a Teo server app.
new
Create an app.
Examples
Create an app
main_namespace
Retrieve the main namespace from the app. Namespace is where models, handlers,
decorators and pipeline items are defined. See Namespace
.
Examples
Retrieve the main namespace
main_namespace_mut
Retrieve the main namespace from the app. This is the mutable version.
Examples
Retrieve the mutable main namespace
setup
Attach some code to run after the database is connected.
Examples
Run custom setup code
program
Define a custom program to run with Teo CLI.
Examples
Define a custom program
run
Start the Teo server app.
Example
Run an server app
Namespace
Namespace is where things are defined and organized.
is_main
Whether the namespace is the main namespace.
is_std
Whether the namespace is the builtin standard namespace.
path
Get the namespace's path.
Example
Namespace's path
namespace
Get the namespace's child namespace by name or None
.
namespace_mut
Get the namespace's mutable child namespace by name or None
.
namespace_mut_or_create
Get the namespace's mutable child namespace. If not present, create and return.
namespace_at_path
Get the namespace's child namespace at path.
namespace_mut_or_create_at_path
The the namespace's child namespace at path. If not present, create and return.
define_model_decorator
Define a new model decorator on a namespace.
Example
Define a custom model decorator
define_model_field_decorator
Define a new model field decorator on a namespace.
Example
Define a custom model field decorator
define_model_relation_decorator
Define a new model relation decorator on a namespace.
Example
Define a custom model relation decorator
define_model_property_decorator
Define a new model property decorator on a namespace.
Example
Define a custom model property decorator
define_pipeline_item
Define a custom pipeline item on a namespace.
Example
Define a custom pipeline item
define_transform_pipeline_item
Define a transformer pipeline item. This is a shortcut to define_pipeline_item
.
Example
Define a custom transformer
Define a custom transformer which errors
define_validator_pipeline_item
Define a validator pipeline item. This is a shortcut to define_pipeline_item
.
Example
Define a custom validator pipeline item with bool return value
Define a custom validator pipeline item with string return value
Define a custom validator pipeline item which errors
define_callback_pipeline_item
Define a callback pipeline item. This is a shortcut to define_pipeline_item
.
Example
Define a custom callback pipeline item
Define a custom callback pipeline item which errors
define_compare_pipeline_item
Define a compare pipeline item. This is a shortcut to define_pipeline_item
.
Example
Define a custom compare pipeline item
define_middleware
Define a middleware on a namespace.
Example
Define a custom middleware
define_handler
Define a custom route handler on a namespace.
Example
Define a custom route handler
define_handler_group
Define a handler group on a namespace.
Example
Define a custom handler group
define_model_handler_group
Define model handlers on a namespace.
Example
Define a custom model handler group
handler::Group
A handler group is a container for defining custom route handlers.
define_handler
Define a custom route handler on a handler group.
Example
Define a custom route handler
Request
A request represents an HTTP request.
method
Retrieve the request's method.
path
Retrieve the request's path.
query_string
Retrieve the request's query string.
content_type
Retrieve the request's content type.
headers
Retrieve the request's headers.
readonly::HeaderMap
The HeaderMap
struct represents readonly headers on a request.
keys
Retrieve the header map's keys.
len
Retrieve the length of the header map.
contains_key
Whether the headers contain a specific key.
get
Retrieve the value of a header entry by key
.
Response
The Response
struct represents an HTTP response.
empty
Create an empty response.
Example
Create an empty response
string
Create a string response.
Example
Create a simple text response
teon
Create a Teon response.
html
Create an HTML response.
Example
Create an HTML response
data
Create a Teon response which contains a data
field.
data_meta
Create a Teon response which contains a data
field and a meta
field.
error
Create an error response.
file
Create a file response.
Example
Create a file response
redirect
Create a redirect response.
Example
Create a redirect response
set_code
Set the response code.
code
Retrieve the response code.
headers
Retrieve the response headers.
body
Retrieve the response body.
readwrite::HeaderMap
The HeaderMap
struct represents readwrite headers on a response.
keys
Retrieve the header map's keys.
len
Retrieve the length of the header map.
contains_key
Whether the headers contain a specific key.
get
Retrieve the value of a header entry by key
.
set
Set a new value of a header entry at key
.
Body
Represents a response body.
is_empty
Whether this response body is empty.
is_file
Whether this response body is a file.
as_file
Retrieve the file response path.
is_text
Whether this response body is text.
as_text
Retrieve the text response string.
is_teon
Whether this response body is teon.
as_teon
Retrieve the response teon value.
teon!
Declare a Teo extended JSON object.
Examples
Declare a Teon object
Entity model
API documentation for generated model entities.
find_many
Find many objects with params same as findMany
handler.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
finder | Yes | &Value | The finder |
Examples
Find all users
Find users filtered by name
Find users ordered by createdAt
Find users with posts
find_unique
Find a unique object with params same as find_unique
handler.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
finder | Yes | &Value | The finder |
Examples
Find a unique user
find_first
Find an object with params same as find_first
handler.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
finder | Yes | &Value | The finder |
Examples
Find a user
count_objects
Count objects in the model.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
finder | Yes | &Value | The finder |
Examples
Count objects
count_fields
Count fields in the model.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
finder | Yes | &Value | The finder |
Examples
Count objects
aggregate
Aggregate on the model.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
finder | Yes | &Value | The finder |
Examples
Aggregate on the model
group_by
Group by on the model.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
finder | Yes | &Value | The finder |
Example
Group by on the model
new
Create a new model object.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
values | Yes | impl AsRef<Value> | The create data |
Examples
Create a new Post
default
Create an empty model object.
Signature
Examples
Create a default empty post
Entity object
is_new
Returns true if object is new.
Signature
Examples
Check if a post is new
is_modified
Returns true if object is modified.
Signature
Examples
Check if a post is modified
set
Set values to an object. The onSet
pipeline is triggered.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
values | Yes | impl AsRef<Value> | The set data |
Examples
Set values to a user
update
Update values on an object.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
values | Yes | impl AsRef<Value> | The update data |
Examples
Update values on a user
save
Save an object.
Signature
Examples
Save a post
delete
Delete an object.
Signature
Examples
Delete a post
to_teon
Convert the object to a teon Value
.