Monday, February 04, 2013

RESTful Templates and Binds

Using a HTTP GET, the passing of variable is quite simple.  All that is needed is to make the URI Template include them.  I this example "myget?a={a}&b={b}"  The values of a and b are converted into a bind variable for use in the sql statement.



With this Resource Template definition, the results are


$ curl  "https://apex.oraclecorp.com/pls/apex/raptor/test/myget?a=hello&b=bye"
{"items":[{"a_value":"hello","b_value":"bye"}]}


Now a POST is even easier to turn value into binds.  Then URI Template in this case is just "mypost".  All the posted values are converted into binds.


With this Resource Template definition, the results are


$ curl -X POST --data "A=hello&B=bye" https://apex.oraclecorp.com/pls/apex/raptor/test/mypost
A is a bind value of:
hello
B is a bind value of:
bye



Lastly, if you post in JSON those are also converted to bind variable.

$ curl -X POST -H "Content-Type: application/json" --data-ascii '{"A":"hello","B":"bye"}' https://apex.oraclecorp.com/pls/apex/raptor/test/mypost
A is a bind value of:
hello
B is a bind value of:
bye

Disqus for Kris' Blog