Multiple possible inputs for API endpoint

Options

This is definitely basic…

I have a table that has several fields that are table references. In my app there are times when I'll want to query that table with one or more of those table reference fields as a filter. Is it best practice to setup a single endpoint that has all possible input parameters, and setup the query logic to ignore empty parameters?

When I tried creating a new endpoint with just one of the input parameters, I got an error that said the name was already used (I copied the naming convention "table_name/{inputfield_id}"). Not seeing one in my list of existing endpoints. So this leads to my best practice question.

TIA

Best Answer

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Answer ✓
    Options

    Hi @EricP you are correct, it sounds like one endpoint with "ignore empty values" used in the query conditions is the way to go.

    In regards to the naming issue, please see this section of our documentation for more details and let me know if we can clarify anything.

Answers

  • Lefteris - blupry.com
    Options

    Hello @EricP,

    Not sure if I got your question right, but I am going to give it a try.

    I guess you tried having more than one endpoints, which with one way or the other were serving the same purpose, with small differences based on the input.

    In general, the best practice is considered to avoid having the frontend of your application decide what endpoint it should use based on some factors.

    So, according to that, it is best to use is_null and/or is_empty Xano filters, to create a condition with different responses based on the inputs.

  • EricP
    EricP Member
    Options

    Thanks for the replies. The last section of the reference documentation makes a lot of sense.