Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 598f761114877e66bb274dd7b085c6b94e5a6db7 0 parents
@tj tj authored
Showing with 138 additions and 0 deletions.
  1. +11 −0 Makefile
  2. +48 −0 Readme.md
  3. +79 −0 bin/burl
11 Makefile
@@ -0,0 +1,11 @@
+
+PREFIX = /usr/local
+BIN = burl
+
+install:
+ cp -f bin/$(BIN) $(PREFIX)/bin/$(BIN)
+
+uninstall:
+ rm -f $(PREFIX)/bin/$(BIN)
+
+.PHONY: install uninstall
48 Readme.md
@@ -0,0 +1,48 @@
+
+# Better curl(1)
+
+ `burl(1)` is a tiny shell script augmenting `curl(1)` with some helpful shortcuts
+ to make your day a little bit better.
+
+## Installation
+
+ $ make install
+
+## Optional hostname
+
+ By default `burl(1)` will assume "http://localhost:3000", however you
+ can alter this by exporting `BURL` in your terminal session:
+
+```
+BURL=http://site-im-testing.com
+$ burl /pathname
+```
+
+## -j, --json DATA
+
+ __POST__ data as "Content-Type: application/json":
+
+```
+$ burl -j {"name":"tobi"} http://local/user
+```
+
+## Expressive header fields
+
+ With `burl(1)` you can define header fields without `-H`:
+
+```
+$ burl If-None-Match etag /users
+$ burl If-None-Match etag Accept: application/json /users
+```
+
+## Accept shorthand
+
+ Currently `.json`, `.text` and `.html` shorthands are
+ available and set the Accept header field for you:
+
+```
+$ burl /users
+$ burl /users .json
+$ burl /users .text
+$ burl /users .html
+```
79 bin/burl
@@ -0,0 +1,79 @@
+#!/usr/bin/env bash
+
+args=
+debug=
+BURL=${BURL:-http://localhost:3000}
+ws="[[:space:]]"
+
+#
+# output usage
+#
+
+usage() {
+ cat <<EOF
+
+ Usage: burl [options] <url>
+
+ Options:
+
+ -j, --json <data> issue an application/json request
+
+ Examples:
+
+ $ burl /users
+ $ burl /users .json
+ $ burl /users .text
+ $ burl /users .html
+ $ burl /search?query=foo
+ $ burl --json '{"name":"tobi"}' /user
+ $ burl Accept: application/json /users
+ $ burl If-None-Match: etag /users
+ $ burl -X GET --json '{"query":"something"}' /search
+
+EOF
+}
+
+# parse args
+
+while test $# -ne 0; do
+ arg=$1; shift
+ case $arg in
+ --debug)
+ debug=1
+ ;;
+ -j|--json)
+ json=$1; shift
+ curl="$curl -H 'Content-Type: application/json' -d '$json'"
+ ;;
+ *:)
+ val=$1; shift
+ args="$args -H \"$arg $val\""
+ ;;
+ /*)
+ args="$args $BURL$arg"
+ ;;
+ .html)
+ args="$args -H Accept:text/html"
+ ;;
+ .txt|.text)
+ args="$args -H Accept:text/plain"
+ ;;
+ .json)
+ args="$args -H Accept:application/json"
+ ;;
+ -h|--help)
+ usage
+ exit
+ ;;
+ *)
+ if [[ $arg =~ $ws ]]; then
+ args="$args \"$arg\""
+ else
+ args="$args $arg"
+ fi
+ ;;
+ esac
+done
+
+test $debug && echo "curl $args"
+eval "curl $args"
Please sign in to comment.
Something went wrong with that request. Please try again.