Node-red 物联网教程7: API接口(从入门到入土)

Node-red官网为我们提供了详细的API接口,便于我们基于Node-red进行二次开发.

但接口API过于详细,很多小伙伴看了一眼,立刻头皮发麻,骂骂咧咧的就被劝退了.

整理这点API接口,耗费了我一个美好的夜晚,我也快入土了.

1.Node-RED module APIs

1.1 node-red

  • auth

    • @node-red/editor-api.auth

  • events

    • @node-red/runtime_events

      • Functions

        • emit(eventName)

        • on(eventName,listener)

      • Parameters

        • eventName:String

        • listener:function

      • Returns

        • Boolean

  • httpAdmin

    • express application

      • the express application for the editor Admin API

  • httpNode

    • express application

      • the express application for HTTP Nodes

  • log

    • @node-red/util_log

      • addHandler( )

        • Add a log handler function

      • audit( )

        • Log an audit event

      • debug( )

        • Log a message at DEBUG level

      • error( )

        • Log a message at ERROR level

      • info( )

        • Log a message at INFO level

      • log( )

        • Log a message object

      • metric( )

        • Check if metrics are enabled

      • removeHandler( )

        • Remove a log handler function

      • trace( )

        • Log a message at TRACE level

      • warn( )

        • Log a message at WARN level

      • _( )

        • Perform a message catalog lookup

  • nodes

    • access to the internal nodes module of the runtime

      This provides access to the internal nodes module of the runtime. The details of this API remain undocumented as they should not be used directly. Most administrative actions should be performed use the runtime api under node-red.runtime.

  • runtime

    • @node-red/runtime

      • functions

        • init(settings, server, adminApi)

        • isStarted(options)

        • start( )

        • stop( )

        • verison( )

      • Members

        • comms

          • addConnection(options)

          • removeConnection(options)

          • subscrible(options)

          • unsubscribe(options)

        • context

          • delete(options)

          • getValue(options)

        • flows

          • addFlow(opts)

          • deleteFlow(opts)

          • getFlow(opts)

          • getFlows(opts)

          • getNodeCredentials(opts)

          • setFlows(opts)

          • updateFlow(opts)

        • library

          • getEntry(opts)

          • saveEntry(opts)

        • nodes

          • addModule(opts)

          • getIcon(opts)

          • getIconList(opts)

          • getModuleCatelog(opts)

          • getModulueCatalogs(opts)

          • getMobuleInfo(opts)

          • getNodeConfig(opts)

          • getNodeConfigs(opts)

          • getNodeInfo(opts)

          • getNodeList(opts)

          • removeModule(opts)

          • setModuleState(opts)

          • setNodeSetState(opts)

        • projects

          • abortMerge(opts)

          • addRemte(opts)

          • commit(opts)

          • createProject(opts)

          • deleteBranch(opts)

          • deleteProject(opts)

          • getActiveProject(opts)

          • getBranches(opts)

          • getBranchStatus(opts)

          • getCommit(opts)

          • getCommits(opts)

          • getFile(opts)

          • getFileDiff(opts)

          • getFiles(opts)

          • getProject(opts)

          • getRemotes(opts)

          • getStatus(opts)

          • initialseProject(opts)

          • listProject(opts)

          • pull(opts)

          • push(opts)

          • removeRemote(opts)

          • resolveMerge(opts)

          • revertFile(opts)

          • setActiveProject(opts)

          • setBranch(opts)

          • stageFile(opts)

          • unstageFile(opts)

          • updateProject(opts)

          • updateRemote(opts)

        • settings

          • generateUserKey(opts)

          • getRuntimeSettings(opts)

          • getUserKey(opts)

          • getUserSettings(opts)

          • removeUserKey(opts)

          • updateUserSettings(opts)

  • server

    • The HTTP Server used by the runtime

  • settings

    • This provides access to the internal settings module of the runtime.

  • util

    • @node-red/util_util

      • cloneMessage(msg)

      • compareObjects(obj1, obj2)

      • encodeObject(msg, opts)

      • ensureBuffer(o)

      • ensureString(o)

      • evaluateEnvProperty(value, node)

      • evaluateJsonateExpression(expr, msg, callback)

      • evaluateNodePrperty(value, type, node, msg, callback)

      • generateId( )

      • getMessageProperty(msg, expr )

      • getObjectProperty( msg, expr)

      • normaliseNodeTypeName( name )

      • normalisePropertyExpression( str )

      • pareseContextStore( key )

      • prepareJSONateExpression( value, node )

      • setMessageProperty( msg, prop, value, createMissing )

      • setObjectProperty(msg, prop, value, createMissing)

  • init

    • init(httpServer, userSettings)

      • Initialise the Node-RED application

  • start

    • start() → {Promise}

      • Start the Node-RED application

  • stop

    • stop() → {Promise}

      • Stop the Node-RED application

  • version

    • version() → {String}

      • Get the version of the runtime

1.2 @node-red/editor-api

1.3 @node-red/runtime

1.4 @node-red/util

1.5 @node-red/registry

1.6 @node-red/nodes

1.7 @node-red/editor-client

2. Editor UI Widgets

2.1 Editor UI Widgets

  • TypedInput

  • EditableList

  • SearchBox

  • TreeList

2.2 EditableList Widget

  • Options

  • Methods

  • Events

    • Types

2.3 SearchBox Widget

  • Options

    • delay

    • minimumLength

  • Methods

    • change

    • count

    • value

  • Events

  • Types

2.4 TreeList Widget

  • Options

    • data

  • Methods

    • data

    • empty

    • show

  • Events

    • treelistselect

    • treelistmouseout

    • treelistmouseover

  • Types

2.5 TypedInput Widget

  • Options

    • default

    • types

    • typeField

  • Methods

    • type

    • ypes

    • validate

    • value

    • width

  • Events

    • hange

  • Types

    • TypeDefinition

3. Context Store API

3.1 Configuration

3.2 Store Module API

3.3 Methods

  • ontextStore.open()

    • Open the storage ready for use

  • ContextStore.close()

    • Close the storage

  • ContextStore.get(scope, key, callback)

    • Get values from the store

  • ContextStore.keys(scope, calback)

    • Get a list of all keys in the store

  • ContextStore.delete(scope)

    • Delete all keys for a given scope

  • ContextStore.clean(activeNodes)

    • Clean the context store

  • ContextStore.set(scope, key, value, callback)

    • Set values in the store

3.4 Memory Context Store

  • Configuration

  • Options

3.5 Local Filesystem Context Store

  • Configuration

  • Options

  • Implementation details

4. Stroage API

4.1 Configuration

4.2 Promises

4.3 Methods

  • Storage.init(settings)

    • initialise the storage system

  • Storage.getFlows()

    • get the flow configuration

  • Storage.saveFlows(flows)

    • save the flow configuration

  • Storage.getCredentials()

    • get the flow credentials

  • Storage.saveCredentials(credentials)

    • save the flow credentials

  • Storage.getSettings()

    • get the user settings

  • Storage.saveSettings(settings)

    • save the user settings

  • Storage.getSessions()

    • get the user sessions

  • Storage.saveSessions(sessions)

    • save the user sessions

  • Storage.getLibraryEntry(type,name)

    • get a type-specific library entry

  • Storage.saveLibraryEntry(type,name,meta,body)

    • save a type-specific library entry

5. Admin HTTP API

5.1 Authentication

  • Check the authentication scheme

    • Get /auth/login

      { “type”: “credentials”, “prompts”: [ { “id”: “username”, “type”: “text”, “label”: “Username” }, { “id”: “password”, “type”: “password”, “label”: “Password” } ] }

  • Obtain an access token

    • Post /auth/token

      { “access_token”: “A_SECRET_TOKEN”, “expires_in”:604800, “token_type”: “Bearer” }

  • Using the access token

  • Revoking the token

5.2 Types

  • Node

  • Subflow

  • Complete Flow configuration

  • Single Flow configuration

  • Node Module

  • Node Set

5.3 Errors

  • Error response

  • Error codes

5.4 Methods

  • GET/auth/login

    • Get the active authentication scheme

  • POST/auth/token

    • Exchange credentials for access token

  • POST/auth/revoke

    • Revoke an access token

  • GET/settings

    • Get the runtime settings

  • GET/flows

    • Get the active flow configuration

  • POST/flows

    • Set the active flow configuration

  • POST/flow

    • Add a flow to the active configuration

  • GET/flow/:id

    • Get an individual flow configuration

  • PUT/flow/:id

    • Update an individual flow configuration

  • DELETE/flow/:id

    • Delete an individual flow configuration

  • GET/nodes

    • Get a list of the installed nodes

  • POST/nodes

    • Install a new node module

  • GET/nodes/:module

    • Get a node module’s information

  • PUT/nodes/:module

    • Enable/Disable a node module

  • DELETE/nodes/:module

    • Remove a node module

  • GET/nodes/:module/:set

    • Get a node module set information

  • PUT/nodes/:module/:set

    • Enable/Disable a node set

学习更多知识,加QQ群:1098090823
威武网 » Node-red 物联网教程7: API接口(从入门到入土)

提供最优质的资源集合

立即查看 了解详情