Noob Question: One API Endpoint or Multiple?

Options
Brandon Hassler
Brandon Hassler Member
edited June 2023 in ? Working with APIs

Let's say I have a table called /products with 4,000 items. On the front of my site, all of the main searching & filtering will go directly through the /products API endpoint.

But let's say I have other uses of that table, such as:

  • Finding the average price of products that meet certain criteria.
  • Finding the top 5 products that meet a certain criteria.
  • Etc.

Let's say 80% of the website activity is using the /products endpoint to search for products. When it comes to adding other uses of that table (that involve evaluating all of the products in the table based on a set of criteria) is there any wisdom in creating a separate API endpoint for those to "ease the pressure" of the main /products endpoint? Or is it best to use a single endpoint and, based on the inputs, the function stack uses IF/THEN statements to determine the response?

Does that question make sense?

Best Answer

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Answer ✓
    Options

    Hi, @Brandon Hassler! I think in general we would recommend different endpoints. Building a "catch all" query with conditionals is a cool idea in theory, but could end up with a lot of unnecessary API compute used and execution time depending on the volume / complexity of the conditional logic.

Answers