Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to get JSON of route definitions #9

Open
glimow opened this issue Jul 1, 2019 · 2 comments
Open

Ability to get JSON of route definitions #9

glimow opened this issue Jul 1, 2019 · 2 comments

Comments

@glimow
Copy link

glimow commented Jul 1, 2019

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

@Alex-Levacher
Copy link
Owner

Alex-Levacher commented Jul 8, 2019

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?

@glimow
Copy link
Author

glimow commented Jul 9, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants