pier

package module
v0.0.0-...-b324533 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 6 Imported by: 0

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main(handler http.Handler)

Types

type Peer

type Peer struct {
	Handler     http.Handler
	BaseContext func(*http.Request) context.Context
}

func (*Peer) Main

func (p *Peer) Main()

func (*Peer) RoundTrip

func (p *Peer) RoundTrip(req *http.Request) (*http.Response, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL