0

I have the following endpoint which solves this purpose: for a given list of directories, we have to get number of files in them.


@router.get(
    "/getFileCountForMultipleDirectories/{directoryList}/"
)
async def get_file_count_for_all_directories(
    directoryList: list[str]
):
    response_payload = None
    # some logic
    return response_payload


So ideally, this API has to be a GET call. But if the list of directories is huge, and we know there are URL max character limits, how to still achieve the solution using GET call? Using POST call as a hack for this, and then passing the list as payload to it, does not seem right.

davidism
  • 121,510
  • 29
  • 395
  • 339
raghavsikaria
  • 867
  • 17
  • 30

1 Answers1

2

This can be necessary to use a POST request instead of a GET request even if it is not to submit new data. You just don't really have another choice when your inputs are too big for a GET request or you have to re-think your API calls in a "GET friendly" way.

Many API are using POST instead of GET, example: https://developers.google.com/cloud-search/docs/reference/rest/v1/query/search

Benoît Zu
  • 1,217
  • 12
  • 22