Shortly

How to merge lists, received from two REST APIs with the limit and offset parameters, and return merged list as a result of calling the 3rd REST API also with the parameters limit and offset?

Detailed

Given endpoints of two REST APIs like these:

GET api-1/events? limit=10 & offset=20
GET api-2/events? limit=10 & offset=20

Calling of these endpoints return ordered by date lists, for example:

api-1:
[
    { "date": "2024-02-11", "text": "magna aliqua" },    
    { "date": "2024-02-10", "text": "enim ad minim" },
    ...    
    { "date": "2024-02-01", "text": "quis nostrud" }  
]

api-2:
[
    { "date": "2024-02-11", "text": "exercitation ullamco" },    
    { "date": "2024-01-11", "text": "laboris nisi" },
    ...    
    { "date": "2023-04-11", "text": "aliquip ex" }  
]

It needs to write an endpoint for 3rd REST API like this:

GET api-3/events? limit=10 & offset=20

...that return merged ordered list by date of results GET api-1/events and GET api-2/events callings.

The problem has a simple solution for the first page (when offset=0), but for subsequent pages is necessary to make many requests to api-1 and api-2.

Questions

  1. Does the problem have well-known name? I would google it in order to get closer to solving the problem.
  2. How to develop api-3 so that it works optimally enough:
    • to leave the ability to make API requests to api-1 and api-2 in parallel.

I know how to solve the problem in a simple way, but it will become more and more not optimal with the increase in the offset value.

Also, I have the option to change the way api-1, api-2 and api-3 work. I am inclined to replace the order and offset parameters with the dateFrom and dateTo parameters. This will solve the merging problem, but generates other problems on the API client side.

0

There are 0 best solutions below