WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: resty - Little command line REST client  (Read 4651 times)

Offline mocore

  • Hero Member
  • *****
  • Posts: 642
  • ~.~
resty - Little command line REST client
« on: April 24, 2013, 06:48:12 AM »
i have been playing about with something called resty
from https://github.com/micha/resty
flashy demo @ http://jpmens.net/2010/04/26/resty/

Code: [Select]
wget http://github.com/micha/resty/raw/master/resty
tce-load -i curl bash perl5
bash
#
. resty
# eg
resty http://tinycorelinux.net/4.x/x86/tcz
 GET /nano.tcz.info
it works but depends on curl bash and perl5  =[
and im wandering if its possible with some modifications to do without bash ? maby even perl5
so curl.tcz is the only needed dependency  !

put another way
what is stopping this from working with in busybox sh ?



Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: resty - Little command line REST client
« Reply #1 on: April 24, 2013, 08:15:06 AM »
Code: [Select]
curl -G http://tinycorelinux.net/4.x/x86/tcz/nano.tcz.info
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline mocore

  • Hero Member
  • *****
  • Posts: 642
  • ~.~
Re: resty - Little command line REST client
« Reply #2 on: April 24, 2013, 11:01:01 PM »
Code: [Select]
curl -G http://tinycorelinux.net/4.x/x86/tcz/nano.tcz.info

thanks for the suggestion
just curl works without fail (resty is just wrapper for curl)

 ..i have now found my previous post was not so clear even to myself !  :o
 i forget that i have used resty before with only core and curl needed
when i post before looking at th script didnt make much sense to me
i messed about just  enough to see it can work
but it has grown a little more complex over time
 now realize the link above was 'linked' to  the latest revision of resty
and have eventually 'remembered enough' to know  how  some of the bits() of it link up  ;D

so now i found
https://github.com/micha/resty/tree/03c3cbdf6e76df18179f73a337a4e7d292119b79#initial commit
back in the day $h was simple
https://raw.github.com/micha/resty/03c3cbdf6e76df18179f73a337a4e7d292119b79/resty
Code: [Select]
function resty() {
  local RESTY_HOST=`cat ${HOME}/.restyrc 2>/dev/null`
  local method="$1"; shift
  local path="$1"; shift
  local acpt="Accept: application/json";
  local data
  local res

  case "$method" in
    GET|DELETE)
      res=$(curl -s -L -f -H "$accp" -X $method "$@" "${RESTY_HOST}$path")
      ret=$?
      [ "$ret" != "0" ] && resty $ret
      echo "$res"
      return $ret
      ;;
    POST|PUT)
      data="$1"; shift
      res=$(curl -s -L -f -H "$accp" -X $method -d "$data" "$@" \
        "${RESTY_HOST}$path")
      ret=$?
      [ "$ret" != "0" ] && resty $ret
      return $ret
      ;;
    http://*)
      echo "$method" > ${HOME}/.restyrc
      ;;
    *)
      echo "resty: curl: returned error $method" 1>&2
      ;;
  esac
}

function GET() {
  resty GET "$@"
}

function POST() {
  resty POST "$@"
}

function PUT() {
  resty PUT "$@"
}

function DELETE() {
  resty DELETE "$@"
}

case "$1" in
  --pretty=*)
    if [ "${1##*=}" == "on" ]; then
      echo yes
      export RESTY_PRETTY=1
    else
      echo no
      export RESTY_PRETTY=0
    fi
    ;;
  *)
    export RESTY_HOST="$1"
    ;;
esac
something like
Code: [Select]
sed -e 's/function/ /g' ./resty_initial >resty_initial.shand that is just about simple enough for me to understand

also i found
frioux/app-adenosine-prefab - "Adenosine was ported to Perl from resty due to a number of issues."

& that this is the last pre perl  resty from #urlencode square brackets


« Last Edit: April 25, 2013, 03:53:52 PM by dubcore »