Can loopback return CSV format?
Can loopback return CSV format?, if not what is the best way to implement an API that can return multiple formats, for example: JSON, CSV, XML, etc
Hey @cchacons, I believe this page should answer your question: https://docs.strongloop.com/display/public/LB/config.json
To be completely honest, I haven't dealt with anything other than JSON, but I know we do support xml.
For future questions, please post on our google group: https://groups.google.com/forum/#!forum/loopbackjs
We're trying to keep github for bugs and feature requests only so that we can stay on top of them. As for returning CSV, that is not something you would want to do with a RESTful API. I think it would make more sense if you could parse XML from the client.
I am going to close this issue here, but please feel free to start a discussion on the google group, it would be interesting to hear what the community has to say!
@cchacons As per my understanding, if you want to add / extract values from a CSV file (ie use it as a database) you have to create a connector for it.
If you want to use XML instead of JSON then read this -> https://docs.strongloop.com/display/public/LB/LoopBack+FAQ#LoopBackFAQ-CananapplicationrespondwithXMLinsteadofJSON?
But your input / output would still be JSON/XML. I don't think loopback itself is built to support any data format apart from these two. Maybe someone from the core team can answer that.
CSV is not very widely used as a data interchange format. It breaks down when you use relational / hierarchical data. My advice would be to use JSON (fat free as compared to XML) if you can, XML for legacy data systems and on your front end / backend write a converster that can parse CSV to JSON and vice versa, Eg: https://github.com/wdavidw/node-csv
@gaurav21r @richardpringle, for better or worse, CSV has been a very widely used data interchange format for a long time and across many industries. Though I'd agree with you to stay away from it for machine to machine interactions, being able to process and generate CSV files is probably the most widely recurring requirement across industries I have run into, whether it is an accountant downloading a statement into Excel and uploading it into their accounting system, or a lab assistance uploading a report into their LIMS system.
Hence IMHO being able to easily produce or consume such a format ( but understanding its limitations) would be a significant feature for many people using loopback as an integration platform.
@steegi Totally agree with you! And I think the real success of CSV has been the success of Excel! Everyone wants an Excel Import and an Excel Export! But I still think CSV belongs in App land not Network land.
Hierarchical data and data with relationships is really hard to model in CSV. Stuff like XML and JSON handle almost all cases of data beautifully!
Loopback (like other ORMs) should concentrate on Database CRUD Operations and Network Operations (if any). Your app should be capable of importing / exporting CSV. The link I've mentioned will pretty much do whatever you want in CSV!
While many arguments that people make are solid, there are definitely use cases for outputting data as CSV directly from the server rather than going to the client first. This simple solution works to achieve that: https://stackoverflow.com/a/31389086/5551593
After having left LoopBack and forked in close proximity to the banking industry, I've seen the extensive usage of CSVs. With that, I've also seen some serious problems with CSVs, their text encoding, and handling multiple internationalization standards. CSVs are too difficult to normalize such that they are easily consumable by another application.
It is much better to use libraries such as csvtojson and manage your csvs without file uploads and downloads as @ataft is suggesting