user5507535
user5507535

Reputation: 1800

How can I pass REST query parameters as optional in Oracle Application Express Listener?

In Oracle Application Express Listener, we can create REST endpoints with a URI, lets say users?limit={limit} where limit it the maximum number of rows to fetch.

The problem is that if we specify a URI like that and try to access just users expecting to get all users, I receive a 404 error because the server can't find that URI.

The question is, is it possible to have these query parameters as optional?

I don't know what version of Apex we have, it looks like this: enter image description here

One idea I had of to solve this, is a hack it's follow: Declare the URI as users{params}, where params would be all parameters and then parse the parameters in PL/SQL, this would work but very hacky indeed.

Upvotes: 0

Views: 1676

Answers (1)

mike
mike

Reputation: 36

You don't need to explicitly define the query parameters in the URL. You can just reference them as bind variables in the source.

For example, if i have a GET resource for employees table

../example/employees

the source of the resource can be

select * from emp where mgr = :mgr or :mgr is null

If I call ../example/employees all employees will be returned (mgr is null)

but if I call ../example/employees?mgr=7839 only the employees with the manager 7839 will be returned.

I can also call ../example/employees?mgr=7839&limit=2 and the results will be limited to 2.

Check out this link for Jeff which has a good example

https://www.thatjeffsmith.com/archive/2017/03/a-tale-of-two-styles-of-uris-and-parameters-words/

Upvotes: 2

Related Questions