Skip to content

Latest commit

 

History

History
511 lines (370 loc) · 10.4 KB

File metadata and controls

511 lines (370 loc) · 10.4 KB

API: Object

Navigation

APIs

create

Create a new object.

Request

POST /api/object/create

Parameters in body

Name Type Description
name string The name of the object.
properties ObjectProperty[] The properties of the object.
description string or NULL The description of the object.
parentId string or NULL The parent id of the object.
allowAnonymous boolean Whether the object is accessible by anonymous users.

Response

200 OK (Object ID)
400 Bad Request
401 Unauthorized
404 Not Found

Example

    curl -i 
    -X POST
    -H "Content-Type: application/json"
    -d '{
        "name": "LED",
        "description": "This is LED",
        "properties": [
            {
                "key": "status",
                "value": 0,
                "canHaveHistory": true,
                "historyLimit": 100,
                "mqttProperty":{
                    "display": true,
                    "subscribe": false
                }
            },
            {
                "key": "brightness", 
                "value": 10, 
                "canHaveHistory": true, 
                "historyLimit": 100,
                "mqttProperty":{
                    "display": true,
                    "subscribe": true
                }
            }
        ],
        "allowAnonymous": true
        }'
    http://localhost:3000/api/object/create

list

List all objects.

Request

GET /api/object/list

URL Parameters

Name Type Description
viewProperties boolean The properties to be displayed.
viewType array or something string The type of the view.

Response body

Name Type Description
id string The id of the object.
name string The name of the object.
parentId string or NULL The parent id of the object.
updatedAt string The last update date of the object.
properties string[]` The children of the object.
properties if viewType == array then ObjectProperty[] else {[key:string]: value} The properties of the object.
description string or NULL The description of the object.
allowAnonymous boolean Whether the object is accessible by anonymous users.
systemObject boolean Whether the object is a system object.

Response

200 OK (Object array)
401 Unauthorized
403 Forbidden

Example

    curl -i 
    -X GET
    -H "Content-Type: application/json"
    http://localhost:3000/api/object/list

list/ids

List all objects ID`s.

Request

GET /api/object/list/ids

Response

200 OK (Object ID`s array)
401 Unauthorized
403 Forbidden

Example

    curl -i 
    -X GET
    -H "Content-Type: application/json"
    http://localhost:3000/api/object/list/ids

list/:id

Return the object with the given id.

Request

GET /api/object/list/:id

Parameters in URL

Name Type Description
id string The id of the object.

URL Parameters

Name Type Description
viewProperties boolean The properties to be displayed.
viewType array or something string The type of the view.

Response body

Name Type Description
id string The id of the object.
name string The name of the object.
parentId string or NULL The parent id of the object.
updatedAt string The last update date of the object.
children string[] The children of the object.
properties if viewType == array then ObjectProperty[] else {[key:string]: value} The properties of the object.
description string or NULL The description of the object.
allowAnonymous boolean Whether the object is accessible by anonymous users.
systemObject boolean Whether the object is a system object.

Response

200 OK (Object)
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found

Example

    curl -i 
    -X GET
    -H "Content-Type: application/json"
    http://localhost:3000/api/object/list/5f9f1b9b-1b5a-4b1f-9c1c-1b5a4b1f9c1c

get/:id

Get an object.

Request

GET /api/object/get/:id

Parameters in URL

Name Type Description
id string The id of the object.

Response

200 OK
400 Bad Request
401 Unauthorized
404 Not Found

Example

    curl -i 
    -X GET
    -H "Content-Type: application/json"
    http://localhost:3000/api/object/get/5f9f1b9b-1b5a-4b1f-9c1c-1b5a4b1f9c1c

get-root

Get the root objects ID`s.

Request

GET /api/object/get-root

Response

200 OK
401 Unauthorized
404 Not Found

Example

    curl -i 
    -X GET
    -H "Content-Type: application/json"
    http://localhost:3000/api/object/get-root

get/:id/children

Get the children of an object.

Request

GET /api/object/get/:id/children

Parameters in URL

Name Type Description
id string The id of the object.

Response

200 OK (Objects ID`s array)
400 Bad Request
401 Unauthorized
404 Not Found

Example

    curl -i 
    -X GET
    -H "Content-Type: application/json"
    http://localhost:3000/api/object/get/5f9f1b9b-1b5a-4b1f-9c1c-1b5a4b1f9c1c/children

get/:id/:prop/history

Get the history of an object property.

Request

GET /api/object/get/:id/:prop/history

Parameters in URL

Name Type Description
id string The id of the object.
prop string The name of the property.

Response

200 OK
{
    current: value,
    history: [
        {
            value: value,
            date: date
        },
        ...
    ]
}

400 Bad Request
401 Unauthorized
404 Not Found

Example

    curl -i 
    -X GET
    -H "Content-Type: application/json"
    http://localhost:3000/api/object/get/5f9f1b9b-1b5a-4b1f-9c1c-1b5a4b1f9c1c/status/history

update/:id

Update an object.

Request

PUT /api/object/update/:id

Parameters in URL

Name Type Description
id string The id of the object.

Parameters in body

Name Type Description
name string or NULL The name of the object.
description string or NULL The description of the object.
allowAnonymous boolean or NULL Whether the object is accessible by anonymous users.
parentId string or NULL The parent id of the object.
children string[] or NULL The children of the object.

Response

200 OK
400 Bad Request
401 Unauthorized
404 Not Found

Example

    curl -i 
    -X PUT
    -H "Content-Type: application/json"
    -d '{
            "name": "LED",
            "description": "This is LED",
            "allowAnonymous": true,
            "parentId": "45345345-1b5a-4b1f-9c1c-1b5a4b1f9c1c",
            "children": ["453453453-1b5a-4b1f-9c1c-1b5a4b1f9c1c"]
        }'
    http://localhost:3000/api/object/update/5f9f1b9b-1b5a-4b1f-9c1c-1b5a4b1f9c1c

update/:id/object

Update the object of an object.

Request

PUT /api/object/update/:id/object

Parameters in URL

Name Type Description
id string The id of the object.

Parameters in body

Type Description
ObjectProperty[] The object of the object.

Response

200 OK
400 Bad Request
401 Unauthorized
404 Not Found

Example

    curl -i 
    -X PUT
    -H "Content-Type: application/json"
    -d '[
            {
                "key": "status",
                "value": true,
                "canHaveHistory": true,
                "historyLimit": 100
            }
        ]'
    http://localhost:3000/api/object/update/5f9f1b9b-1b5a-4b1f-9c1c-1b5a4b1f9c1c/object

set/:id

Set the value of an object property.

Request

GET /api/object/set/:id?key=:key&value=:value

Parameters in URL

Name Type Description
id string The id of the object.
key string The name of the property.
value string The value of the property.

Response

200 OK
400 Bad Request
401 Unauthorized
404 Not Found

Example

    curl -i 
    -X GET
    -H "Content-Type: application/json"
    http://localhost:3000/api/object/set/5f9f1b9b-1b5a-4b1f-9c1c-1b5a4b1f9c1c?key=status&value=true

remove/:id

Remove an object.

Request

DELETE /api/object/remove/:id

Parameters in URL

Name Type Description
id string The id of the object.

Response

200 OK
400 Bad Request
401 Unauthorized
404 Not Found

Example

    curl -i 
    -X DELETE
    -H "Content-Type: application/json"
    http://localhost:3000/api/object/remove/5f9f1b9b-1b5a-4b1f-9c1c-1b5a4b1f9c1c

search

Search objects.

Request

GET /api/object/search

Parameters in URL

Name Type Description
query string The query to search for.

Response

200 OK
400 Bad Request
401 Unauthorized

Example

    curl -i 
    -X GET
    -H "Content-Type: application/json"
    http://localhost:3000/api/object/search?query=LED