I have a task where I need to transform XML
files and transform those into JSON
as fast as possible. I.e. I receive XML files on a FTP server and as soon as a file hit the server then I need to upload that file in JSON format into a NOSQL database. Currently my idea is
POST
request to a FastAPI
endpoint (and use lxml
for the actual transformation from xml to json).But I can't figure out how my API endpoint should look like? I'd probably skip any validations etc. since that will introduce lag and milliseconds is valuable.
@mr-bjerre I'm not sure how detailed of a response you are looking for, but I think this is a good use case for UploadFile
(documented here).
This would let you upload the XML using a file interface (submitted over HTTP as a multipart/form-data
), would keep it in memory (assuming it wasn't too large, in which case it would be transparently spooled to disk), wouldn't impose any validation overhead, and you could then handle the received file however you wanted (e.g., parsing with lxml and storing in your database however you like, with as much or as little validation as appropriate).
Perfect answer thanks !
Thanks for the help @dmontagu! : 馃嵃
Thanks @mr-bjerre for reporting back and closing the issue.