MCPcopy Index your code
hub / github.com/WebThingsIO/webthing-node / post

Method post

lib/server.ts:437–466  ·  view source on GitHub ↗

* Handle a POST request. * * @param {Object} req The request object * @param {Object} res The response object

(req: express.Request, res: express.Response)

Source from the content-addressed store, hash-verified

435 * @param {Object} res The response object
436 */
437 post(req: express.Request, res: express.Response): void {
438 const thing = this.getThing(req);
439 if (thing === null) {
440 res.status(404).end();
441 return;
442 }
443
444 const keys = Object.keys(req.body);
445 if (keys.length !== 1) {
446 res.status(400).end();
447 return;
448 }
449
450 const actionName = keys[0];
451 let input = null;
452 if (req.body[actionName].hasOwnProperty('input')) {
453 input = req.body[actionName].input;
454 }
455
456 const action = thing.performAction(actionName, input);
457 if (action) {
458 const response = action.asActionDescription();
459 action.start();
460
461 res.status(201);
462 res.json(response);
463 } else {
464 res.status(400).end();
465 }
466 }
467}
468
469/**

Callers 1

constructorMethod · 0.95

Calls 4

asActionDescriptionMethod · 0.80
getThingMethod · 0.45
performActionMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected