-
Notifications
You must be signed in to change notification settings - Fork 7
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
[cli] ability to generate RESTful routes #65
Comments
Hey @HashanCP 👋 I really like this idea 👍 it will definitively be a new feature to implement. Have you some CLI examples that generate files (I guess laravel and angular have popular CLI that works in the same way) to estimate what could be the best DX for such a command? |
there are few i found while investigating the idea. But since rails and laravel are MVC-based in both tools its its bound to 'Controller'. Regardless
Note that, in Artisan, In rails its bit weird, command will be I guess when it comes to restapify, due to its file-based routing, idea of generating RESTful routes is the important bit. I feel like, we can decide on a much better cli interface for restapify. |
In Laravel, can be used to create just only "api routes" that create all routes except 'create' and 'edit' (GET)methods. This is the kind of output more suitable for restapify i guess. More on Laravel Official Doc |
Thanks for the research 👍 Yeah I really like your initial idea since it's only about REST routes and nothing else. So we can imagine that
and
So that the CLI only generate what the user ask for. Then we could add some flags like |
i made a small shell script to get a feel for a potential CLI for restapify. I created bash script(assuming a *nix system) in a Gist. I've put your ideas into the mix as well. Syntax There will be 2 new commands.
|
Hey @HashanCP this Is really awesome and like the idea of the Concerning the states there is a little miscomprehension. A state in Restapify can be just a simple string and not necessary a HTTP status code identifier so you could have a state I also figured out that to make this command work, user need to have a Thanks a lot for your interest and time that you spend on this project 💪 |
yes, you are right...i made a mistake in the script and last comment...updated both accordingly 😄 looking forward for your input about further implementation cheers |
@HashanCP would you be interrested to implement this feature in the project if you have time ? 👍 |
sure @johannchopin, happy to 🤩. i will post exact implementation details after going through current codebase. Feel free to suggest any additional features you'd want in this implementation. 😉 |
Perfect so lets discuss the implementation of it 👍 So it can be used like : restapify generate dogs
# or restapify generate dog
restapify generate dogs/[dogId] Which will create only the GET endpoints. First we need to verify that there is a config file I used commanderjs for the cli which is pretty straightforward, you can find some implementation of it in cli.ts file. This command will have several flags:
|
@johannchopin i played with cli code and thought of a more concise interface for it.
couple of things to note here that will be in final implementation for above commands
In my opinion this adds generating routes via CLI bit smart and much friendly for adoption due to express-like passed over cli. And as discussed issuing these commands will ONLY generate GET endpoints
Now for flags, I'd like to propose a change to flags which are different from our initial discussion but will address above concerns. Let me break it down(in terms of commanderjs).
|
Hey @HashanCP 👋 Just ping me if you need some help of any kind. Also if you had some other issues feel free to post them I would have time this week 👍 |
Hi Johan,
creating files over and over can be tedious over time. So as a start, a common use case when designing APIs is ability to generate RESTful routes as below
restapify generate dogs
will generate following files in current directory
resulting in following routes
We can put default(opinionated) content into generate files according best practices in the industry. In my opinion this would give user a quick starting point and improved DX.
There are similar implementations of developer tooling in the world of Ruby on Rails, Laravel although i am not aware of the exact commands to do so. Anyway, this is an abstract idea just for now. It should be possible(in future) to create error states via cli when passed as arguments/flags such as
restapify generate dogs --error=404:NOT_FOUND --error=400:BAD_REQUEST
what is you opinion on implementing such a feature?
cheers
The text was updated successfully, but these errors were encountered: