consul-node
consul-node copied to clipboard
Result object property naming/casing
Hi!
I'm about to make some contributions to consul-node, since we're about to start using Consul and need a NodeJS client.
Now I'm mainly looking for some guidance related to coding standards and property mappings.
In the current version of consul-node, all the properties returned from the HTTP API are transformed/mapped to other names (mainly lower casing). Is this the way to go when implementing support for new endpoints? It would reduce some overhead to simply serve the resulting JSON (object) right back :-)
And possibly increase compatibility with the HTTP API, since new properties would be automatically supported, etc.
If mapping is the way to go; what are the naming rules for the transformed properties? I'm thinking of maybe implementing a more general solution, which simply can remap the properties of any object based on some kind of hash map for translation ({"Service": "service", "ID": "id"}
etc).
I'm currently looking at implementing the support for the /health
endpoint and the response was a bit more complex than the ones from the endpoints currently supported. Further down is an example.
Regards, Emanuel
[
{
"Node":
{
"Node":"api-node1",
"Address":"127.0.0.1"
},
"Service":
{
"ID":"testservice",
"Service":"testservice",
"Tags":
[
"node"
],
"Port":80
},
"Checks":
[
{
"Node":"api-node1",
"CheckID":"service:testservice",
"Name":"Service 'testservice' check",
"Status":"passing",
"Notes":"",
"Output":"",
"ServiceID":"testservice",
"ServiceName":"testservice"
},
{
"Node":"api-node1",
"CheckID":"serfHealth",
"Name":"Serf Health Status",
"Status":"passing",
"Notes":"",
"Output":"",
"ServiceID":"",
"ServiceName":""
}
]
}
]
That's fine, feel free to remove the casing in a PR along with whatever awesome stuff you got!