httpu

package module
v0.0.0-...-01c0eb4 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2018 License: GPL-2.0 Imports: 7 Imported by: 0

README

httpu

httpu

httpu is a terminal first, general purpose HTTP client, designed to get you interacting with all aspects of an HTTP API within just a few seconds. This makes it a good tool for testing out various endpoints, methods, payloads - so you are able to see what's being sent, and what response you are then getting.

Getting started

Installing
macOS
brew tap httpu/httpu
brew install httpu
Building from source
cd $GOPATH
mkdir -p src/github.com/hazbo
cd src/github.com/hazbo
git clone [email protected]:hazbo/httpu.git
cd httpu
make
Basic usage

I started writing this project whilst working with the Moltin API, which is a headless commerce API, so there are a few examples using that, if you want to play around with that, just head to the website, get your API keys and you are good to go!

Once httpu has been installed, you can get started either by first pulling down the preconfigured packages:

httpu pull

And then loading the configuration of a package into httpu like so:

httpu new moltin

or by creating your own configuration. A basic project may look like the following:

mkdir -p httpbin/requests
touch httpbin/project.json httpbin/requests/ip.json

httpbin/project.json

{
  "project": {
    "url": "https://nghttp2.org/httpbin",
    "resourceFiles": [
      "httpbin/requests/ip.json"
    ]
  }
}

httpbin/requests/ip.json

{
  "kind": "request",
  "name": "ip",
  "spec": {
    "uri": "/ip",
    "method": "GET"
  }
}

Once you have that setup, you're ready to run httpu!

httpu new httpbin

When the UI has loaded, typing in ip (the name of the request) into the prompt, followed by hitting enter will run that request and you will be able to see the response body in the right-hand window. In this case, it will simply just return your IP address from which the request has been made.

Keybinding Description
Up Switch to command mode
Down Switch to default mode
Left Move cursor to request view
Right Move cursor to response view
Ctrl+w Move cursor from request / response view to the prompt
Ctrl+s Switch the cursor from request view to response view
Ctrl+c Quit

To see what commands are available, switch to command mode, then type in list-commands.

Advanced usage

httpu is able to look at a JSON response, take a given value and store it in memory, to then be used for another request. This in-memory store is called the stash. So for example, in the previous example, if you wanted to store the IP address that is returned, and use it else where, the request file may look like this:

httpbin/requests/ip.json

{
  "kind": "request",
  "name": "ip",
  "spec": {
    "uri": "/ip",
    "method": "GET",
    "stashValues": [
      {
        "name": "my-ip",
        "jsonPath": "origin"
      }
    ]
  }
}

and then in a seperate request you can then access it, once the ip request has been made, like so:

httpbin/requests/get.json

{
  "kind": "request",
  "name": "get",
  "spec": {
    "uri": "/get?ip=${stash[ip]}",
    "method": "GET"
  }
}

with ${stash[ip]} being a variable created after running the ip request.

For more examples for advanced usage including the stash, sending request data, using environment variables etc... head over to the packages repo and check out the example I've started creating for the Moltin API.

Coming soon

  • A view to display response headers (priority)
  • Creating a request flow
  • Creating tests for a request or set of requests
  • Various UI tweaks
  • An HTTP API interface

Known issues

This project is in its very early stages, so there will be things that need fixing. One issue at the moment is a problem with parsing stashed variables into request data before a request has been made. If this happens, and you are seeing ${stash[var_name]}, just fire the request again and it should work.

Contributing

  • Fork httpu
  • Create a new branch (git checkout -b my-feature)
  • Commit your changes (git commit)
  • Push to your new branch (git push origin my-feature)
  • Create new pull request

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigureFromFile

func ConfigureFromFile(filePath string) error

ConfigureFromFile reads in a base JSON config file and decodes it into Config

Types

type Config

type Config struct {
	Project Project `json:"project"`
}

Config is a wrapper for the Base config.

type Project

type Project struct {
	URL           url.URL            `json:"url"`
	ResourceFiles resource.FilePaths `json:"resourceFiles"`
	ProjectPath   string

	Requests map[string]request.Request
}

the base URL which is then extended in "request" Resources using a URI and a path within a Variant.

Headers that are set here will apply to all requests, but can be overridden within an individual request / variant.

The resources are read as []string from the JSON, however as they are being unmarsheled, the JSON for the filename is fetched and is unmarsheled into the Resources that exist within Base.

func Session

func Session() Project

func (*Project) UnmarshalJSON

func (p *Project) UnmarshalJSON(j []byte) error

UnmarshalJSON is an implemenation of json.Unmarshaler and is used to parse the URL into a native url.URL type and the Headers into http.Header.

If an invalid URL is passed, an error will occur at this point.

Directories

Path Synopsis
api
cmd
ui
utils

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳