Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add JSON shorthands

  • Loading branch information...
commit d83481224220bfddfbd8eb7db638f00ce8e08309 1 parent 6c83a0f
TJ Holowaychuk authored
Showing with 33 additions and 1 deletion.
  1. +16 −0 Readme.md
  2. +17 −1 bin/burl
16 Readme.md
View
@@ -41,6 +41,22 @@ $ burl PATCH -d 'email=tobi@learnboost.com' /user/12
$ burl DELETE /users
```
+## JSON request bodies
+
+ Usually when you want to request with some JSON you do something like:
+
+```
+$ curl -X PATCH -d '{"name":"tobi"}' -H "Content-Type: application/json" http://localhost:3000/user/12
+```
+
+ With `burl(1)` you can simply add a JSON array or object after the HTTP verb:
+
+```
+$ burl PATCH '{"name":"tobi"}' /user/12
+$ burl POST '[1,2,3]' /numbers
+```
+
+
## Expressive header fields
With `burl(1)` you can define header fields without `-H`:
18 bin/burl
View
@@ -48,7 +48,23 @@ while test $# -ne 0; do
json=$1; shift
args="$args -H 'Content-Type: application/json' -d '$json'"
;;
- GET|POST|PUT|HEAD|DELETE|OPTIONS|PATCH|TRACE|COPY|LOCK|\
+ POST)
+ args="$args -X $arg"
+ c=${1:0:1}
+
+ # json array
+ if test "$c" = "["; then
+ args="$args -d \"$1\" -H \"Content-Type: application/json\""
+ shift
+ fi
+
+ # json object
+ if test "$c" = "{"; then
+ args="$args -d \"$1\" -H \"Content-Type: application/json\""
+ shift
+ fi
+ ;;
+ GET|PUT|HEAD|DELETE|OPTIONS|PATCH|TRACE|COPY|LOCK|\
MKCOL|MOVE|PROPFIND|PROPPATCH|UNLOCK|REPORT|MKACTIVITY|\
CHECKOUT|MERGE|NOTIFY|SUBSCRIBE|UNSUBSCRIBE)
args="$args -X $arg"
Please sign in to comment.
Something went wrong with that request. Please try again.