Skip to content
/ pier Public

A "clientless" implementation of HTTPie embedded in Go.

License

Notifications You must be signed in to change notification settings

deref/pier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pier

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.

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

go get github.com/deref/pier

Code

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.

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:

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 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.

About

A "clientless" implementation of HTTPie embedded in Go.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages