Comments (4)
Thanks a lot for the ideas! Looks good for me to go explore things, will get back if something more could be done! π
from restish.
It's possible to add your own custom formats, auth, commands, etc to Restish pretty easily, for example the main.go
setup just looks like this:
cli.Init("restish", version)
// Register default encodings, content type handlers, and link parsers.
cli.Defaults()
// Register format loaders to auto-discover API descriptions
cli.AddLoader(openapi.New())
// Register auth schemes
cli.AddAuth("oauth-client-credentials", &oauth.ClientCredentialsHandler{})
cli.AddAuth("oauth-authorization-code", &oauth.AuthorizationCodeHandler{})
// Run the CLI, parsing arguments, making requests, and printing responses.
cli.Run()
You can do a cli.Root.AddCommand(&cobra.Command{......})
before calling cli.Run()
.
If you prefer to just get a bunch of pre-configured commands and inject those into your CLI, I haven't tried that but you might be able to. There is a cli.Load(entrypoint string, root *cobra.Command)
you can try to use. You'll still need to cli.AddLoader(openapi.New())
if you want it to recognize OpenAPI.
Any improvements to make this easier or better are welcome! π
Edit: I'm also contemplating whether it would be worth supporting some kind of plugin or scripting functionality to enable custom commands. π€
from restish.
Thanks a lot for the pointers, will try them out soon! π As for the extensibility aspects, it would be great, at least for me, if I can just hook in my commands which aren't necessarily talking to the API. Also maybe a way to customise the handler of the OperationId, the way i was thinking before I found restish is taking a map like:
map[string]func(params map[string]any) error{
"opid1": func(params map[string]any) error {
// some potential side-effects
return err
},
...
}
and passing it along to the init or something? I think having something like this enables more custom behaviour while still keeping the underlying things same?
from restish.
As for the extensibility aspects, it would be great, at least for me, if I can just hook in my commands which aren't necessarily talking to the API.
Using cli.Root.AddCommand(&cobra.Command{......})
lets you add any custom command you want, for example:
cli.Init("my-cli", "1.0.0")
cli.Root.AddCommand(&cobra.Command{
Use: "hello",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
// You can do anything you want here, no need to talk to any API!
fmt.Printf("Hello, %s!\n", args[0])
},
})
cli.Run()
Then you can try it out:
$ go run . hello lispyclouds
Hello lispyclouds!
from restish.
Related Issues (20)
- Request: add support for deflate encoding HOT 2
- Finish Gron Mon HOT 1
- Accèssing response body and headers not possible at same time HOT 1
- Add a help mode which excludes global flags
- Refreshing API definition interacts strangely with CLI flags and CachedTransport HOT 1
- gron output fails on keys containing "." HOT 2
- Question: Is it possible to send multipart/form-data request? HOT 2
- runtime error: invalid memory address with specific OpenAPI specs HOT 1
- separating commands by tags HOT 1
- Question: is it possible to generate request body from open api examples
- Header case modification makes restish unusable for some APIs with case senstive headers
- Downloading Restish on Windows? HOT 1
- http-basic password prompt is shown clear text
- Create API Specific Commands from PostgREST
- Support Flags for positional arguments and request bodies HOT 3
- Getting `Caught error: runtime error: invalid memory address or nil pointer dereference` trying to import basic OpenAPI spec HOT 1
- (Feature Request) - Allow restish to be used in non-interactive mode HOT 2
- Feature request: Per project configuration
- Allow base path elements to be ignored
- Stack Overflow error when renderSchemaInternal() is called
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from restish.