https://github.com/deref/pier
A "clientless" implementation of HTTPie embedded in Go.
https://github.com/deref/pier
Last synced: 3 months ago
JSON representation
A "clientless" implementation of HTTPie embedded in Go.
- Host: GitHub
- URL: https://github.com/deref/pier
- Owner: deref
- License: mit
- Created: 2021-06-20T01:25:29.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-02-26T00:09:08.000Z (over 2 years ago)
- Last Synced: 2024-06-19T11:30:03.301Z (almost 2 years ago)
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pier
A "clientless" implementation of [HTTPie][1] embedded in Go.
Pier converts any implementation of [http.Handler][2] to a CLI tool with the
convenient argument syntax and features of HTTPie.
## Motivation
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.
## Usage
### Install
```bash
go get github.com/deref/pier
```
### Code
```go
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:
```bash
go run ./example /echo message=hello
```
See [https://httpie.io/docs](https://httpie.io/docs) for more detailed documentation on command line usage.
### Customization
Right now, the only interesting option is BaseContext, which works similar to
that of Go's http.Server. Specify options by constructing a Peer:
```go
peer := &pier.Peer{
Handler: app.Handler,
BaseContext: func(*http.Request) context.Context {
return context.Background()
},
}
peer.Main()
```
## Status
Stable enough for development use (which is the intended use anyway!)
Pier is implemented in terms of [nojima/httppie-go][3] and
inherits its behavior completely. See the httpie-go readme for details.
## Trivia
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.
[1]: https://httpie.io/
[2]: https://golang.org/pkg/net/http/#Handler
[3]: https://github.com/nojima/httpie-go