A "clientless" implementation of HTTPie embedded in Go.
Pier converts any implementation of http.Handler to a CLI tool with the convenient argument syntax and features of HTTPie.
Go's compile and execute cycle is fast enough that you can practice "REPL-driven development" using Bash. However, this practice requires authoring custom CLI tools, which can be tedious. Furthermore, if you're developing an HTTP service, the work of building a CLI tool feels redundant with all the work you're doing to build a nice HTTP API. With Pier, no server or file-watcher is required during iteration.
go get github.com/deref/pier
import (
"github.com/deref/pier"
"example.com/your/app"
)
func main() {
pier.Main(app.Handler)
}
Then simply invoke with HTTPie syntax.
There is an example app in this repository. Try this:
go run ./example /echo message=hello
See https://httpie.io/docs for more detailed documentation on command line usage.
Right now, the only interesting option is BaseContext, which works similar to that of Go's http.Server. Specify options by constructing a Peer:
peer := &pier.Peer{
Handler: app.Handler,
BaseContext: func(*http.Request) context.Context {
return context.Background()
},
}
peer.Main()
Stable enough for development use (which is the intended use anyway!)
Pier is implemented in terms of nojima/httppie-go and inherits its behavior completely. See the httpie-go readme for details.
Where does the name come from?
In the past the author has referred to CLI tools in this style that bypass the client/server as operating in "peer" mode. HTTPie + Peer = HTTPier. Shorter is better and "Pier" seemed to be mostly disused on Github, so here we are.