HTTP response example

Hi guys,
I googled the best practices to implement an API patterns like headers, status code and body keys, but just found some examples.

Also I am trying to understand template node.

Appreciate any help and docs.

So many ways to skin this cat.....

I like to use a function node for my header needs.

[{"id":"f3653817.6b169","type":"http in","z":"cdb1eebd.d2859","name":"","url":"/camera/api/server_stats_static","method":"get","upload":false,"swaggerDoc":"","x":220,"y":140,"wires":[["2917c400.ee40f4"]]},{"id":"19e7ceac.618571","type":"http response","z":"cdb1eebd.d2859","name":"","statusCode":"","headers":{},"x":910,"y":140,"wires":[]},{"id":"58c0b0e6.4c3de8","type":"function","z":"cdb1eebd.d2859","name":"headders and status code","func":"\n//msg.payload = (was already sent)\n\nmsg.statusCode = \"200\";\n\nmsg.headers = {};\nmsg.headers['X-Robots-Tag'] = \"noindex\";\nmsg.headers['no-fs-camera'] = \"true\";\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":730,"y":140,"wires":[["19e7ceac.618571"]]},{"id":"2917c400.ee40f4","type":"http request","z":"cdb1eebd.d2859","name":"Server Stats static","method":"GET","ret":"obj","paytoqs":"ignore","url":"http://127.0.0.1:8888/static.json","tls":"","persist":false,"proxy":"","authType":"","x":490,"y":140,"wires":[["58c0b0e6.4c3de8"]]}]

Screenshot from 2021-03-08 22-21-20

I also like using headers over parameters in the url for talking server to server.

I like to use JSON formatted objects for my payload (response) but will also use headers as well. depends on the need/use

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.