Forum Stats

  • 3,815,381 Users
  • 2,259,010 Discussions
  • 7,893,063 Comments

Discussions

POST sent to ORDS for APEX grid filter, how is it possible it works?

Hello,

We use 19c DB, ORDS 21.3 and APEX 21.2.

We have a APEX grid based on REST source. In APEX we declared a REST data source of type Oracle REST Data Services with 2 operations. One GET / Fetch rows and one GET / Fetch single row.

In ORDS we declared one GET of type Collection query (select * from my_table) and one GET of type Collection query item (select * from my_table where id = :id).

The APEX grid displays data correctly.

However when we use a filter in the grid, we noticed in the APEX debug that a POST is sent to ORDS with filter details in the body.

How is it possible it works as in ORDS not POST method is declared and when we send the same POST flow manually (by Postman for example) it returns a 405 Method Not Allowed error message.

Currently the filter in the grid works but as soon as we place ORDS behind our API gateway (for production environment) it doesn't work (the gateway blocks POST method as there is not POST method declared in ORDS).

Thanks for your help.

Tagged:

Answers

  • thatJeffSmith-Oracle
    thatJeffSmith-Oracle Distinguished Product Manager Posts: 8,510 Employee

    can you record a HAR in your browser so we can see what you're talking about?

    Also, just making sure, you're doing a GET from an ORDS based REST API from a different database where you have APEX running, right?

  • User_I14MW
    User_I14MW Member Posts: 7 Green Ribbon
    edited May 10, 2022 4:47PM

    Hello,

    Thanks for your answer.

    I made an example on apex.oracle.com.

    I have 2 GET handlers, one select * for emp and one for select * by empno:


    I have an APEX REST data source based on these ORDS API:

    I have an APEX grid based on this REST data source:

    If I use a filter in the grid, a POST is sent to ORDS and it works but there is no POST method declared in ORDS:

    APEX grid with filter

    APEX debug with POST method call with filter in the request body

    How ORDS is able to answer to the POST method when there is no POST method declared in ORDS?

    Thanks

  • User_I14MW
    User_I14MW Member Posts: 7 Green Ribbon

    Hello,

    Any feedback on this topic?

    Thanks

  • Carsten Czarski-Oracle
    Carsten Czarski-Oracle Consulting Member of technical Staff Munich, GermanyMember Posts: 1,313 Employee

    Hi,

    you are using the "ORDS" REST Data Source type in APEX, is that correct?

    Using this REST Source type means that APEX has some "know how" about what the REST Endpoint can do and what not. For instance, "ORDS" provides filtering, ordering and pagination at the server side, so APEX pushes these filters down (see the "ORDS filter grammar" in ORDS documentation).

    Well, ORDS allows to pass filters and order bys to the REST Endpoint either by URL ("q" parameter) or in the request body, using a POST request. As Filters for an interactive grid can become larger, and APEX wants to avoid URL length limits to be hit, APEX uses the POST method by default, even if the configured HTTP method is POST. That is specific to the ORDS REST Data Source type - for other REST Source types (e.g. Simple HTTP) you don't see that.

    So, to make the long story short: APEX uses POST as it knows that ORDS accepts the POST request and the filter syntax in the request body.

    BTW: This is rather an APEX than an ORDS question, so the "APEX" discussion forum would be the better place, actually.

    I hope this helps

    -Carsten

  • User_I14MW
    User_I14MW Member Posts: 7 Green Ribbon

    Hi Carsten,

    Thanks a lot for your answer.

    When you write "APEX uses the POST method by default, even if the configured HTTP method is POST", you mean "APEX uses the POST method by default, even if the configured HTTP method is GET", right?

    And that means that even if only GET method is defined in ORDS, ORDS is able to give an answer to the POST method, is it correct?

  • Carsten Czarski-Oracle
    Carsten Czarski-Oracle Consulting Member of technical Staff Munich, GermanyMember Posts: 1,313 Employee

    HI,

    And that means that even if only GET method is defined in ORDS, ORDS is able to give an answer to the POST method, is it correct?

    Correct. To be accurate, this depends on the Handler Type, which you used when creating the REST Service for ORDS. If you're using a REST Enabled Table/View, or the "Query (Feed)" Handler types for your REST API, then it will accept either GET or POST. The client can send off a GET request, and append the Filters using the "q" URL parameter, or the client can execute a POST request and send the filter as the request body.

    If you're using a PL/SQL Handler in ORDS (so you're providing the PL/SQL code, which emits the response output, yourself), then the client has to stick with the configured handler type. However, in that case, the filtering syntax would not work also, as that only works with the Query Handler Type or REST Enabled objects.

    Best regards

    -Carsten

  • User_I14MW
    User_I14MW Member Posts: 7 Green Ribbon

    Very clear explanation. Thank you.

    Just a last detail, how ORDS is able to know that the POST it receives is a "true" POST and it should execute the POST handler or it is not a "true" POST and it should execute the GET handler with the parameters in the body?