Lumie
Lumie copied to clipboard
Ability to get JSON of route definitions
It would be interesting being able to programmatically access the detected routes, e.g the data used to generate this:
> node index.js
======== ROUTES ========
[Battery]
public get [/api/battery/]
[Consumption]
public get [/api/consumption/]
[Production]
public get [/api/production/]
public get [/api/production/solar]
public get [/api/production/wind]
========================
Example app listening at http://127.0.0.1:3000
It would allow automatic API discovery and -why not- the creation of a client SDK
Hello @glimow, you're right it's interesting. I will implement it. It will allow creating custom reporter as well instead of the default one you just shown above. Can describe the use case you'll be solving with this new enhancement?
Thanks @Alex-Levacher :)
My use case would be to create a custom client js SDK that would read route definition schema from a custom api route like api/config
and would generate the resulting functions on the run. For example something with an API like
const sdk = SDK.init(" http://127.0.0.1:3000")
//.... in an async function
const solarData = await sdk.production.solar.get()
const windData = await sdk.production.wind.get()
// etc...
For some projects, I see two main advantages to this approach : it automatically wraps the REST api with more convenient javascript functions and it enforces some convention on the client side.