Coreserver REST API¶
Coreserver作为MistMesh的设备管理平台,还有很长的路要走。
数据实体¶
以下是Coreserver的缩略版openapi说明。
[GET] https://mist.h-iot.com/backend/api/v3/help
{
"/api/v3/alerts": {
"GET": "Return list of alerts",
"POST": "Inserts new alert, returns alert data.",
"PUT": "Updates alerts from {id: {fields to update}}, returns [{alert data}, ]."
},
"/api/v3/alerts/<int:id_alert>": {
"GET": "Get alert data by ID",
"PUT": "Update alert by ID, like set ack flag"
},
"/api/v3/alerts/count": {
"GET": "Get alert count"
},
"/api/v3/areas": {
"GET": "Get details of all areas.",
"POST": "Insert a new area."
},
"/api/v3/areas/<int:id_area>": {
"DELETE": "Deactivate area by ID",
"GET": "Get area details by ID",
"PUT": "Update area details"
},
"/api/v3/clients": {
"GET": "Get list of clients",
"POST": "Inserts new client, adds current user as site admin, returns client data"
},
"/api/v3/clients/<int:id_client>": {
"GET": "Get client settings by ID",
"PUT": "Update client data by ID"
},
"/api/v3/controllers": {
"GET": "Return list of controllers",
"POST": "Create new controller"
},
"/api/v3/controllers/<int:id_controller>": {
"DELETE": "Deactivate controller by ID",
"GET": "Get controller by ID, with feature IDs.",
"PUT": "Update controller data by ID"
},
"/api/v3/controllers/limbo/<int:id_gateway>": {
"GET": "Return list of limbo controllers matching gateway serial number",
"POST": "Insert limbo controllers matching gateway serial number"
},
"/api/v3/controllers/multiple": {
"POST": "Mass-inserts/updates a list of controllers, returns lists of\ncreated/updated items with all fields set like {controllers: [{item}, ]}, \nor a map of list indexes to errors like\n{0: {missing: [fields lacking value],\n invalid: [fields with invalid value],\n noforeign: [foreign key fields referring to missing rows],\n reserved: [fields with values already used in existing rows, e.g. same guid as another device]},\n 1: {duplicate: True},\n 2: {importduplicate: True if row is the same as another row in import data},\n 3: {idabsent: True} for primary keys not present in db,\n 4: {error: 'unexpected error message'}}"
},
"/api/v3/daemons/settings": {
"GET": "Returns a list of daemon settings",
"POST": "Inserts new daemon settings"
},
"/api/v3/daemons/settings/<int:id_daemon_settings>": {
"DELETE": "Deactivates daemon settings by ID",
"GET": "Returns a daemon settings by ID",
"PUT": "Updates daemon settings by ID"
},
"/api/v3/devices": {
"GET": "Return a list of devices",
"POST": "Add a device."
},
"/api/v3/devices/<category>": {
"GET": "Return a list of devices",
"POST": "Add a device."
},
"/api/v3/devices/<category>/<int:id_device>": {
"DELETE": "Deactivate a device by ID",
"GET": "Get device details by ID",
"PUT": "Modify a device details by ID"
},
"/api/v3/devices/<category>/count": {
"GET": "Return device count"
},
"/api/v3/devices/<category>/multiple": {
"POST": "Mass-inserts/updates a list of devices in specified device category,\nreturns lists of created/updated items with all fields set\nlike {devices: [{item}, ], controllers: [{item}, ]}, \nor a map of list indexes to errors like\n{0: {missing: [fields lacking value],\n invalid: [fields with invalid value],\n noforeign: [foreign key fields referring to missing rows],\n reserved: [fields with values already used in existing rows, e.g. same controller as another device],\n importreserved: [fields with unique values same as another row in import data],\n 1: {duplicate: True},\n 2: {importduplicate: True if row is the same as another row in import data},\n 3: {idabsent: True} for primary keys not present in db,\n 4: {error: 'unexpected error message'}}"
},
"/api/v3/devices/<int:id_device>": {
"DELETE": "Deactivate a device by ID",
"GET": "Get device details by ID",
"PUT": "Modify a device details by ID"
},
"/api/v3/devices/count": {
"GET": "Return device count"
},
"/api/v3/events": {
"GET": "Return list of events"
},
"/api/v3/events/<int:id_device>": {
"GET": "Get events for single device"
},
"/api/v3/events/aggregate": {
"GET": "Get list of events aggregated per fk_device and fk_event_type,\nas [{fk_client, fk_site, fk_device, fk_devices, fk_event_type, dt, value}, ]."
},
"/api/v3/events/count": {
"GET": "Get event count"
},
"/api/v3/events/latest": {
"GET": null
},
"/api/v3/help": {
"GET": "Print available functions."
},
"/api/v3/help/openapi.json": {
"GET": "Show API endpoints in OpenAPI-compatible format."
},
"/api/v3/locales": {
"GET": "Returns a list of locales",
"POST": "Inserts new locale"
},
"/api/v3/locales/<int:id_locale>": {
"DELETE": "Deactivates locale by ID",
"GET": "Returns a locale by ID",
"PUT": "Updates locale by ID"
},
"/api/v3/poll": {
"GET": "Returns changed/new rows as {table: [{row}, ], ..}.",
"POST": "Returns changed/new rows as {table: [{row}, ], ..}."
},
"/api/v3/reference/alerttypes": {
"GET": "Return all alert types"
},
"/api/v3/reference/controllertypes": {
"GET": "Return all controller types",
"POST": "Insert new controller type data"
},
"/api/v3/reference/controllertypes/<int:id_controller_type>": {
"DELETE": "Deactivate controller type data by ID",
"GET": "Get controller type name and other data by controller type ID",
"PUT": "Update controller type data by ID"
},
"/api/v3/reference/devicecategories": {
"GET": "Return a list of device categories"
},
"/api/v3/reference/devicecategories/<int:id_category>": {
"GET": "Return a device category by ID"
},
"/api/v3/reference/devicetypes": {
"GET": "Return a list of device types",
"POST": "Insert new device type data"
},
"/api/v3/reference/devicetypes/<category>": {
"GET": "Return a list of device types",
"POST": "Insert new device type data"
},
"/api/v3/reference/devicetypes/<category>/<int:id_device_type>": {
"DELETE": "Deactivate device type data by ID",
"GET": "Return a device type by ID",
"PUT": "Update device type data by ID"
},
"/api/v3/reference/devicetypes/<category>/multiple": {
"POST": "Mass-inserts/updates a list of luminaire types, returns lists of\ncreated/updated types with all fields set like {device_types: [{item}, ]},\nor a map of list indexes to errors like\n{0: {missing: [fields lacking value], invalid: [fields with invalid value]},\n 1: {duplicate: True},\n 2: {error: 'unexpected error message'},\n 3: {idabsent: True} for primary keys not present in db}"
},
"/api/v3/reference/devicetypes/<int:id_device_type>": {
"DELETE": "Deactivate device type data by ID",
"GET": "Return a device type by ID",
"PUT": "Update device type data by ID"
},
"/api/v3/reference/eventtypes": {
"GET": "Returns a list of event types"
},
"/api/v3/reference/eventtypes/<int:id_event_type>": {
"GET": "Returns an event type by ID"
},
"/api/v3/reference/features": {
"GET": "Return list of feature types"
},
"/api/v3/reference/features/<int:id_feature>": {
"GET": "Returns a feature by ID"
},
"/api/v3/reference/languages": {
"GET": "Returns a list of languages"
},
"/api/v3/reference/privileges": {
"GET": "Returns a list of privileges"
},
"/api/v3/reference/roles": {
"GET": "Returns a list of roles",
"POST": "Inserts new role"
},
"/api/v3/reference/roles/<int:id_role>": {
"DELETE": "Deactivates role by ID",
"GET": "Returns a role by ID",
"PUT": "Updates role by ID"
},
"/api/v3/reference/ruletypes": {
"GET": "Return all rule types",
"POST": "Insert new rule type data"
},
"/api/v3/reference/ruletypes/<int:id_rule_type>": {
"DELETE": "Deactivate rule type data by ID",
"GET": "Returns a rule type by ID",
"PUT": "Update rule type data by ID"
},
"/api/v3/rules": {
"GET": "Return list of rules",
"POST": "Insert new rule"
},
"/api/v3/rules/<int:id_rule>": {
"DELETE": "Deactivate rule by ID",
"GET": "Get rule by ID",
"PUT": "Update rule data by ID"
},
"/api/v3/rules/<int:id_rule>/apply": {
"DELETE": "Unapply this rule"
},
"/api/v3/rules/<int:id_rule>/renew": {
"POST": "Renew all applied rules of this rule"
},
"/api/v3/rules/applied": {
"GET": "Return list of active applied_rules",
"POST": "Apply rule to single device"
},
"/api/v3/rules/applied/<int:id_applied_rule>": {
"DELETE": "Deactivate applied rule by ID",
"GET": "Get applied rule by ID"
},
"/api/v3/rules/applied/<int:id_applied_rule>/reactivate": {
"POST": "Force re-evaluation of rule in the \"rejected\" or \"expired\" state by ID"
},
"/api/v3/rules/applied/<int:id_device>": {
"GET": "Return list of active applied rules by device ID"
},
"/api/v3/rules/applied/<int:id_device>/defaults": {
"GET": "Get active default applied rules on a device",
"POST": "Applies default rules to device if not already applied, returns [{applied_rules row}, ]."
},
"/api/v3/rules/applied/clear": {
"POST": "Remove all rule application from all specified devices."
},
"/api/v3/rules/applied/commissioning": {
"DELETE": "Deactivate commissioning rules on all devices",
"GET": "Return {commissioning_rules_active: are any applied}",
"POST": "Apply commissioning test rules all supported devices,\nreturn freshly applied [{applied_rules row}, ]."
},
"/api/v3/rules/applied/commissioning/<int:id_device>": {
"DELETE": "Deactivate commissioning rule by device ID",
"GET": "Returns applied commissioning rule by device ID",
"POST": "Apply commissioning rule to device, return {applied_rules row}"
},
"/api/v3/rules/applied/count": {
"GET": "Return active applied_rules count"
},
"/api/v3/rules/applied/defaults": {
"DELETE": "Removes default rules from specified or all devices.",
"GET": "Get active default rules on all devices",
"POST": "Applies default rules to all devices where not applied,\nreturns [{applied_rules row}, ]."
},
"/api/v3/rules/applied/multiple": {
"DELETE": "Delete rule application from multiple devices",
"POST": "Apply rule to multiple devices, return [{applied_rule}, ]"
},
"/api/v3/rules/applied/reactivate": {
"POST": "Force re-evaluation of all rules in the \"rejected\" or \"expired\" states."
},
"/api/v3/rules/internal": {
"GET": "Return list of internal rules",
"POST": "Insert new internal rule"
},
"/api/v3/rules/internal/<int:id_rule>": {
"GET": "Get internal rule data by ID",
"PUT": "Update internal rule by ID, return data"
},
"/api/v3/sites": {
"GET": "Return list of sites",
"POST": "Create new site"
},
"/api/v3/sites/<int:id_site>": {
"GET": "Get site by ID",
"PUT": "Update site data by ID"
},
"/api/v3/token": {
"GET": "Return {token, username, id} if HTTP auth username-password valid."
},
"/api/v3/token/blank": {
"GET": "Return {token, username, id} if HTTP auth username-password valid."
},
"/api/v3/token/client/<int:id_client>": {
"GET": "Return {token, username, id} if HTTP auth username-password valid."
},
"/api/v3/token/client/<int:id_client>/site/<int:id_site>": {
"GET": "Return {token, username, id} if HTTP auth username-password valid."
},
"/api/v3/token/info": {
"GET": "Return {client: {}, site: {}, clients: [{}], sites: [{}]} for current session."
},
"/api/v3/token/site/<int:id_site>": {
"GET": "Return {token, username, id} if HTTP auth username-password valid."
},
"/api/v3/token/test": {
"GET": "Return 400 if HTTP auth username contains invalid token."
},
"/api/v3/users": {
"GET": "Return list of users",
"POST": "Create new user"
},
"/api/v3/users/<int:id_user>": {
"DELETE": "Deactivate user by ID",
"GET": "Get user by ID",
"PUT": "Update user data by ID"
},
"/api/v3/users/self": {
"GET": "Get current user data",
"PUT": "Update current user data"
},
"/api/v3/version": {
"GET": "Show application version."
}
}
更详细的说明请直接访问:https://mist.h-iot.com/backend/api/v3/help/openapi.json。
实现方式¶
客户的服务器后端需要作为REST API的客户端来访问我们的服务端口。
评估代码¶
MistMesh 提供如下评估代码:
- dashboard,基于Flask;
- Scripts V1,基于命令行,最初的测试代码,仅做参考,不再主动维护;
- Scripts V2,基于命令行和Python3。