Returning data to the user (Good API Design)
So now I have developed an application for which I am trying to write an API. The application will ideally return the strings back to the user. The API cannot "return" data in the normal programmatic sense, because an unknown number of rows can be sent from the application. On Unix systems, is it a bad idea to pass this data to the user via a named pipe? I'm having trouble finding information on the details of creating an API. Thanks for any help.
a source to share
The API cannot "return" data in the normal programmatic sense, because an unknown number of rows can be sent from the application. On Unix systems, is it a bad idea to pass this data to the user via a named pipe?
Unix usually uses a program to output its data, as much data as you want, maybe a lot of data, by writing the data to "standard output". The user can pipe this output to a screen or file, or pipe it as input to another program (which can filter data, for example).
I am having trouble finding any information about the details of creating an API.
http://www.faqs.org/docs/artu/ is pretty famous, fwiw: http://www.faqs.org/docs/artu/ch07s02.html#plumbing says something (with some example) about using pipes , to output data from one program to another program.
a source to share
Depends on the application. If it's a short-lived command line tool, then the read-from-stdin / write-to-stdout model works fine. grep / sed / awk / perl will take care of the post-processing of the data. If it's a daemon, then a fifo or socket might be a good idea, although you'll have to think about some kind of client-server protocol in that thread. Going one step further to providing a library that knows this protocol and giving the application developer some consistent set of functions to communicate with your application would be a real API. This classic client-server, for example, is how most databases work.
a source to share