Search code examples
api-design

API status response for partial data being fetched from db?


What would be appropriate status response in the case if client requested specific range of entries like so.

GET /cars?ids=1,2,3,4,5

And the database returned only part of the collection, so the client will get only.

['car1', 'car2', car4']

I'm hesitating between 202 and 206. But what would be more or less standard way dealing with such situation?


Solution

  • I think you should go with the 206.

    202 is for

    Its purpose is to allow a server to accept a request for some other process (perhaps a batch-oriented process that is only run once per day) without requiring that the user agent's connection to the server persist until the process is completed.

    206 is used when

    The server has fulfilled the partial GET request for the resource.

    Which is your case.

    Read the specs : https://www.rfc-editor.org/rfc/rfc7233#section-4.1