Brandon Keepers - @AdrianP Quick question for y...

@AdrianP Quick question for you. I was just looking through the source for your flags plugin to learn from it, and noticed it calls initFlagsEndpoint in start instead of in registerWithRouter. Can you help me understand why? https://github.com/panaaj/signalk-flags/blob/main/src/index.ts#L109
4 Replies
Brandon Keepers
Brandon KeepersOP4mo ago
ahh, I might have just realized why. Is it because you wanted to publish the API as /resources/flags and not /plugins/flags? Followup question then: why publish your own endpoints instead of using the resource-provider api? Just curious and wanting to learn
AdrianP
AdrianP4mo ago
Correct, registerWithRouter roots the endpoint under /plugins (from memory). The resources API pattern is centred around /resourcetype/id where the responses are json. Additional sending file contents of different type (i.e. svg file contents) breaks this pattern hence stepping outside.
Brandon Keepers
Brandon KeepersOP4mo ago
Makes sense. I like the pattern though of still nesting it under resources.
AdrianP
AdrianP4mo ago
Resources is a broad category so it's a good place to put things that don't go in the data model.

Did you find this page helpful?