An open API service indexing awesome lists of open source software.

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.

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