danielgtaylor / restish

Restish is a CLI for interacting with REST-ish HTTP APIs with some nice features built-in
https://rest.sh/
MIT License
900 stars 74 forks source link

Support Flags for positional arguments and request bodies #236

Open thebauda opened 8 months ago

thebauda commented 8 months ago

TLDR; Support accessing positional arguments and request bodies as flags

When a restish command is available that was generated from an endpoint that path parameters and/or takes a request body, the command is structured as so:

restish <api> <command> <positional-argument-1> '{input.json}'

For example, the following endpoint with the following request body POST my-api/v2/orgs/{org_id}/create_user_in_organization

{
  "first_name": string,
  "last_name": string
}

would be called by restish as so

restish my-api create-user-in-organization <org-id> '{"first_name": "foo","last_name": "bah"}'

It would be better if restish could support using flags to pass values to positional arguments and request bodies. The above example could then be called as so:

restish my-api create-user-in-organization --org-id <org-id> --first-name "foo" last-name "bah"
danielgtaylor commented 8 months ago

@thebauda why would this be better? Flags are typically optional while the org-id positional parameter is always required in your example. You can also use the CLI shorthand for the body to save yourself having to type out JSON like this:

restish my-api create-user-in-organization MyOrg first_name: foo, last_name: bah
thebauda commented 8 months ago

@thebauda why would this be better? Flags are typically optional while the org-id positional parameter is always required in your example. You can also use the CLI shorthand for the body to save yourself having to type out JSON like this:

restish my-api create-user-in-organization MyOrg first_name: foo, last_name: bah

I'd like it where required and non-required items can be passed as flags. Not all of my users are familiar with CLI shorthand, and as you stated, writing JSON can be cumbersome and error-prone.

thebauda commented 8 months ago

Would you ever be willing to give my team and I a walkthrough on the Restish project architecture? I'd like to contribute PRs that introduce new features and have you review them.