![]() |
Flecs v3.2
A fast entity component system (ECS) for C & C++
|
This document provides an overview of the REST API. The Flecs REST API enables (web) clients to inspect the contents of the ECS store, by remotely running queries and requesting entities.
The REST API can be enabled in an application by instantiating the EcsRest
/flecs::Rest
component:
When an application uses the app addon FLECS_APP the REST interface can be enabled like this:
To test if the REST API is working, navigate to http://localhost:27750/entity/flecs/core/World. Upon success this request should return a reply that looks like:
When the monitor module is imported, the REST API provides a stats
endpoint with statistics for different time intervals:
When an application uses the app addon FLECS_APP the monitoring can be enabled like this:
For the full C/C++ API reference see the REST addon documentation.
An application with REST enabled can be remotely monitored with the Flecs Explorer. When the application is running with REST enabled, navigate to https://flecs.dev/explorer. This should connect the Explorer to the application.
When the connection is successful, the Explorer should look similar to this:
The remote icon next to the title should be visible. If the connection is not successful it could be that the explorer did not receive a response fast enough. To force the explorer to connect remotely, add ?remote=true
to the request: https://flecs.dev/explorer?remote=true.
If connection issues persist, the browser could be preventing connections to a local application. See the Explorer repository README for more information on how to workaround this and other issues.
Tip: To show the application title in the explorer, pass the command line arguments to ecs_init
/flecs::world::world
:
The search bar in the explorer makes it possible to directly query the ECS storage. A query can be entered in the "Search" box, and needs to be specified in the query DSL (see query manual). An example:
The default query engine used by the search bar is the rules engine, which means it is possible to use features like query variables:
It is also possible to inspect the results of existing queries. This can be done by entering a ?-
, followed by the name of the query. Queries can be given a name by setting the .entity
field to a named entity in C:
In C++ a name can be provided to the query factory method:
This also works for filters and rules. Because systems are queries, the name of a system can be entered to inspect the entities matched by the system:
When a named rule query has variables, variables can be optionally provided as arguments to the query. The following example provides the value Apples
to the query variable food
for query eats_query
, which constrains the results to only show results with Apples
:
The underlying query that was used for this screenshot was created like this:
This section describes the endpoints of the REST API.
The entity endpoint requests data from an entity. The path is the entity path or name of the entity to query for. The reply is formatted according to the JSON serializer Entity type.
The following parameters can be provided to the endpoint:
Add path (name) for entity.
Default: true
Add label (from doc framework) for entity.
Default: false
Add brief description (from doc framework) for entity.
Default: false
Add link (from doc framework) for entity.
Default: false
Add labels (from doc framework) for (component) ids.
Default: false
Add base components.
Default: true
Add component values.
Default: false
Add private components.
Default: false
Add reflection data for component types.
Default: false
Add active alerts for entity.
Default: false
The enable endpoint enables the entity specified by the path by removing the flecs.core.Disabled
component. If the entity does not have the flecs.core.Disabled
component, the endpoint has no side effects.
The disable endpoint disables the entity specified by the path by adding the flecs.core.Disabled
component. If the entity already has the flecs.core.Disabled
component, the endpoint has no side effects.
The delete endpoint deletes the entity specified by the path.
The set endpoint sets components for the entity specified by the path. The data argument uses the same layout as the ids
and values
fields produced by the ecs_entity_to_json
function. An example:
The query endpoint requests data for a query. The implementation uses the rules query engine. The reply is formatted as an JSON serializer Iterator type.
The following parameters can be provided to the endpoint:
Specify the name of an existing query or system.
Skip the first offset number of entities.
Default: 0
Return at most limit number of entities.
Default: 100
Add top-level "ids" array with components as specified by query.
Default: false
Add top-level "id_labels" array with doc names of components as specified by query.
Default: false
Add result-specific "ids" array with components as matched. Can be different from top-level "ids" array for queries with wildcards.
Default: false
Add result-specific "id_labels" array with doc names of components as matched. Can be different from top-level "term_labels" array for queries with wildcards.
Default: false
Add result-specific "sources" array with component source. A 0 element indicates the component is matched on the current (This) entity.
Default: false
Add result-specific "variables" array with values for variables, if any.
Default: true
Add result-specific "is_set" array with boolean elements indicating whether component was matched (used for optional terms).
Default: false
Add result-specific "values" array with component values. A 0 element indicates a component that could not be serialized, which can be either because no reflection data was registered, because the component has no data, or because the query didn't request it.
Default: false
Add result-specific "entities" array with matched entities.
Default: true
Include doc name for entities.
Default: false
Include numerical ids for entities.
Default: false
Include doc name for variables.
Default: false
Include numerical ids for variables.
Default: false
Include measurement on how long it took to serialize result.
Default: false
Add top-level "type_info" array with reflection data on the type in the query. If a query element has a component that has no reflection data, a 0 element is added to the array.
Default: false
The stats endpoint returns statistics for a specified category or period. This endpoint requires the monitor module to be imported (see above). The supported categories are:
world
pipeline
The supported periods are: