• Hi,

    How would you recommend passing 277 options in a custom taxonomy through the REST API?
    I am using WordPress as a headless CMS for a mobile app, so all the information is passed via the REST API. A custom post type will need to select one of out 277 options. This would typically be a custom taxonomy, but I am concerned that it would be slow to read the 277 options in the database and then pass them with all the overhead of 277 records to the mobile app…
    Shall I create a separate endpoint with an array with the 277 values?
    Any elegant suggestion would be great!

    Thanks a lot for you help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator bcworkz

    (@bcworkz)

    Your app needs one of the 277? You should let SQL figure out which is needed and only send that one. SQL is faster at picking out data than anything else at our disposal. It’s what it was built for. You may need a custom route/endpoint to do so, but it’s worth the effort. Include the necessary criteria for selection in the request and let SQL pick out the right option.

    Thread Starter nickb

    (@nickbuc)

    Thanks a lot!
    Sorry my question was not very clear… The user needs to select one option in the app, out of the list of 277, and the app will send that option to WP. I am trying to use the REST API to pass the list of the 277 options to the app, in case that list changes in the future.
    I will create a custom route to send the list of options to the app or code the list in the app. I’ll use SQL for all other actions when I have received the value.

    Moderator bcworkz

    (@bcworkz)

    If all options must be sent out to the client, there’s little choice but to do it. By nature of the API it’s going to be JSON data no matter how you slice it. But no one is going to want to wade through a list of that many choices. Consider some sort of drill down filtering. You then only need to transmit the next level of options each time. There are several more exchanges, but each has much less data and the total data exchange overall is much less.

    But if you must do all at once, maybe it’s an easily searched alphabetical list, in the end it’s likely not all that much data compared to sending an image file or something.

    Thread Starter nickb

    (@nickbuc)

    I agree that 277 is too many… I was also thinking about some sort of drill down filtering as the user types in.
    I could transfer the 277 words at once, through one specific endpoint, as a matrix… It should not be too big and that would limit the overheard that I would get from sending 277 individual options. The app would implement the drill down filtering and the list would not need to be hard coded in the app.
    I could pre-load the same list into a WP custom taxonomy in the backend, to capture and store the selection of the user.

    Moderator bcworkz

    (@bcworkz)

    I like your auto-suggest idea. Limiting options to those with the first couple letters typed would significantly diminish the data transfer needed. The time delay in fetching related options can be a little wonky over slow connections, as it is with any auto-suggest that has to be fetched via Ajax.

    I kinda assumed you were intending to fetch all 277 at once as a JSON array from the beginning, which didn’t strike me as too bad an approach. It would make any auto-suggest implementation much more responsive. You’d need a custom route/endpoint, which isn’t difficult to do.

    Fetching all 277 one at a time through the standard options route would certainly be the worst way to do this. This variation should indeed be avoided at all costs.

    Thread Starter nickb

    (@nickbuc)

    Excellent! Now I have a plan!
    Thanks a lot for your help.

    Moderator bcworkz

    (@bcworkz)

    You’re welcome. Happy coding!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Efficient way to pass 277 options in taxonomy through REST API?’ is closed to new replies.