Christoph's 2 Cents

A Backup for My Brain!

Oracle Developement

ORDS REST: Getting Bind Variables Right

It seems every time I create a REST GET module I have to re-learn how to handle bind variables. So I decided to create a little cheat sheet.

When creating a REST module with a GET handler, you can pass variables wither through the URI or through header variables:

URI Variables:

URI

The URI template needs to have the bind variables in curly brackets (comma separated if multiple binds):

testuri/{id},{ename}

Create a query:

select * 
  from emp
 where empno = :id
   and ename = :ename

Create a parameter for each bind variable:
parameters

I don’t think whether if the Source Type matters. HTTP Header has worked for me. I typically set the parameter name and bind variable name to upper case to avoid any problems.

Test:

Click theĀ Set Bind Variables button to test the handler. Make sure to add a value to all parameters. If you leave a parameter empty, you’ll get an error.

 

Header Variables:

Create the URI without a trailing forward slash:

header

Create the query and parameters as before.

Test:

You’ll have to test this with a REST client like POSTman or CURL:

$ curl -H "id:7788" -H "ename:SCOTT" http://myserver:8080/ords/cmr/hr/testheader

Note when using header variables, you can leave some out without getting an error.

Happy RESTing!