Lumie icon indicating copy to clipboard operation
Lumie copied to clipboard

Ability to get JSON of route definitions

Open glimow opened this issue 5 years ago • 2 comments

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

glimow avatar Jul 01 '19 16:07 glimow

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?

Alex-Levacher avatar Jul 08 '19 08:07 Alex-Levacher

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.

glimow avatar Jul 09 '19 17:07 glimow