Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

zresty

zresty is a zsh resty-like command line tool for testing restful apis powered by httpie.

It borrows its idea from resty which allows setting the static section of the api uri beforehand and then sets up quick access methods for the variable part. Instead of curl the zresty uses the awesome httpie.

Example

Quick Start

If you don't have httpie, then get it first. It's available with apt-get, yum, dnf, brew and pip at least.

Try zresty with

# curl -L https://github.com/Kynde/zresty/raw/master/zresty.plugin.zsh > zresty.plugin.zsh
# . ./zresty.plugin.zsh

or clone the repo and source it from there in your .zshrc like

git clone https://github.com/Kynde/zresty ~/.zsh/zresty
echo '. ~/.zsh/zresty/zresty.plugin.zsh' >> ~/.zshrc

As a plugin

zresty ships as a standard *.plugin.zsh file, so any of the usual zsh plugin managers will pick it up:

# antidote (in your .zsh_plugins.txt)
Kynde/zresty

# antigen
antigen bundle Kynde/zresty

# zinit
zinit light Kynde/zresty

# oh-my-zsh
git clone https://github.com/Kynde/zresty ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zresty
# then add `zresty` to plugins=(...) in ~/.zshrc

Usage

usage: zr [OPTIONS] <URI>

Most options are passed onto http upon each invocation of http methods.
The special option is -H <HTTP-PARAMS> which can be used to pass headers to http for example
Without URI it prints out current options and URI

zresty methods:
	get post put delete

zresty method options:
	currently none

example:
	# . zresty.plugin.zsh
	# zr :3000/api/1.0
	# get /ping

The defaults are lowercase commands zr, get, put, post and delete. Head, patch and options have been left out because they're not very common and tend to conflict with some actual commands. Lowercase was chosen because they're easier to type, but that's easy to change.

The main command name (zr by default) is configurable via ZRESTY_CMD, set before sourcing the plugin. The default used to be z, but zoxide now ships a z of its own that you almost certainly don't want overridden. To get the classic behaviour back:

ZRESTY_CMD=z
. ~/.zsh/zresty/zresty.plugin.zsh

The default options are -b for body only. This is because it allows easy manipulation with jq, e.g. get /user | jq .name.

If any options are given to the call to zr, that default is overridden.

An api-key can be set using -H and headers, e.g.

    # zr -b -H api-key:FOOBAR http://some.where/api

Dependencies

The httpie is needed.

Why?

I really liked the idea of resty, but I'd gotten too used to the powerful arguments and colours of httpie to let it go.

Bash?

Why not, I don't use it, but go ahead and I'll be happy merge a pull request.

About

zsh command line rest api test tool

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages