Home > front end >  Best practice to send the input request to POST endpoint
Best practice to send the input request to POST endpoint

Time:08-27

Iam creating a POST endpoint named /transactions which should accept the below input. What is the best practice to send the input request like the below? Should i use a request body or a input stream or a plain String?

1707341341814,0.0942672968,1482509067
1707341339814,0.0073002568,1585397644
1757341331814,0.0699538547,1652154378
1007341271814,0.0186780608,117212767
1907341261814,0.0331608748,1529565646
1107341331814,0.7496950936,1120653751
1207341291814,0.0866221433,1204727708
1407341338814,0.0382456915,1790856792
1507341311814,0.0524600768,2137711810
1707340341814,0.0320791311,1593887095

CodePudding user response:

I would send a request body and use an already known appendable MIME type, something like CSV. So it will not violate the uniform interface constraint.

If it is a big amount of data and the order is important and you want to send it parallel in multiple chunks, then you can use the Content-Range header for POST-ing too. You just need to return 5o1 if you got such a request and it is not implemented. Other than that you can send it in chunks or in your case records/rows and have a custom unit other than bytes in the range headers. Is using the HTTP Content-Range header appropriate when sending a file in chunks using the POST method? Why is the content-range header stripped from requests in ASP.NET Web API?

As of streaming input in real time e.g. with websockets I don't know, REST is designed for REQREP type of communication for HTTP 1.1, so it is a grey area, but maybe the upper helps.

  • Related