I'm developing an API that given a few parameters, reads the given data, transforms it and returns it as JSON.
Eg. (some logic included)
Request:
POST /myApi/exportAsText
Content-Type: application/json
{
section: array,
answers: array,
targetLevel: int
}
Output:
// Goes through data, create big text
{'text': "blablablabla"}
Currently, I'm using POST requests to send the data, however I think it is against best-practices to use POST requests unless we are creating resources.
Now, you ask me: Why not just use GET requests?
Answer: Url length issues. Some parameters that I'm sending are 3000 chars long
, which is way over the max url length in some browsers (eg. Edge 16 (2047 max length))
.
I've had a look at this post, which is about a very similar topic. They recommend creating a file system that would work the following way:
Send POST request, create a file with text output named using
uuid4()
and return the file name.Send GET Request with the file name, return the file content and delete the file.
If the file, is not acessed in a few minutes, delete it automaticaly.
I would like to know, what you guys think about this approach and if there is other good approach.
Thank you and I apologize if there is any grammar mistakes.
307
with the URI where the content will be served eventually. URI that must be consumed with POST too.