skip to Main Content

I have a rest API that takes longer to populate complete result data (as it iterates the remove directory recursively which is time taking sometimes) during that time the client is keep waiting. once all the data is populated we are sending a response back to the client.

The problem with the above method is the client is keep waiting until all the data is populated.

is there a way in .net, the Rest API sends the data back to the client in chunks as the data keeps on populating? (without client to wait till whole data is generated).

Can you provide a sample of how to achieve the above requirement in .Net ?

2

Answers


  1. It depends how long client should wait.

    For long operations maybe it better to create more endpoints:

    1. endpoint to start operation, returns operation id
    2. endpoint for cheking operation status for given id
      returns response:

      • operation status: completed, in-progress
      • jobs (chunks), chunk:id1 – completed, chunk:id2 – in-progress
    3. endpoint for retrieving jobs (chunks) results – for given operation id and chunk id
    Login or Signup to reply.
  2. The solution depends if the client needs the data all at once or not.

    If data is needed in parts then you should use pagination (in my opinion this is the correct way).

    If data is needed all at once then you should make 2 end-point (one for starting the job in background and one for downloading data once it’s done) and a background worker (Web Jobs or Azure Functions that could store the result in Blob Storage or Database) witch will notify the client when the process is finished.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search