ideas icon indicating copy to clipboard operation
ideas copied to clipboard

Create a Rest Controller scaffold command.

Open BE-Webdesign opened this issue 8 years ago • 8 comments

Hi Folks!

The scaffold commands are really invaluable, and I was wondering if wp-cli could feature a scaffolding command for creating REST API controllers. For the most part controllers are just massive boilerplate (which is good), and I think it would be great to have a wp-cli command to generate that boilerplate. It could by default output routes for EDITABLE, DELETABLE, CREATABLE, and READABLE. Then in one of the flags you could override that to only get what you need. I would be willing to help create these commands, but would first like to know more about the WP CLI process.

Thank you, wp-cli rocks!

BE-Webdesign avatar Sep 22 '17 14:09 BE-Webdesign

👍 I dig the idea.

danielbachhuber avatar Sep 22 '17 14:09 danielbachhuber

👍 I dig the idea.

What are next steps?

BE-Webdesign avatar Sep 22 '17 14:09 BE-Webdesign

@danielbachhuber We should decide whether this should go into the existing, bundled scaffold command (alongside CPTs, taxonomies, etc...), or whether this should be a separate command that you can optionally install.

Given that this is an integral part of WordPress Core and that it seems to get more and more important for normal WP development, I'd go with a PR against wp-cli/scaffold-command to include it as a bundled command.

schlessera avatar Sep 22 '17 14:09 schlessera

Given that this is an integral part of WordPress Core and that it seems to get more and more important for normal WP development, I'd go with a PR against wp-cli/scaffold-command to include it as a bundled command.

I agree with this.

@BE-Webdesign Can you share your proposed output for the routes?

danielbachhuber avatar Sep 22 '17 14:09 danielbachhuber

Can you share your proposed output for the routes?

I would have to think a bit about it first. I can make a gist.

BE-Webdesign avatar Sep 22 '17 14:09 BE-Webdesign

https://gist.github.com/BE-Webdesign/42df5e6117659b7bb8b5066ab4f1c90a

This would be a rough thing, I guess. It's not the full picture.

BE-Webdesign avatar Sep 22 '17 15:09 BE-Webdesign

Ideally, it'd be functional code. What do you think about scaffolding individual routes instead, with command arguments for each of the features that register_rest_route() supports?

danielbachhuber avatar Sep 22 '17 15:09 danielbachhuber

Ideally, it'd be functional code. What do you think about scaffolding individual routes instead, with command arguments for each of the features that register_rest_route() supports?

That would probably be a better starting place, then we could create the controller scaffolding based on those outputs.

BE-Webdesign avatar Sep 22 '17 15:09 BE-Webdesign