How to make Api for Delphi application

Posted on 2011-10-09
Last Modified: 2012-05-12

I have never done such a thing before.
I am thinking of creating of an API interface for my applications written in Delphi.

I am interested in the following:
1.How can I make an api for my Delphi application
2.What are the areas I can use the Api for (at first I thought of data import and export but I am sure there are other useful areas as well)
Question by:starhu
    LVL 4

    Expert Comment

    what will the API will serve?

    you can make your delphi application a WSDL server.... frm here it will generate
    an api where external application can talk to and exchange request..

    LVL 25

    Expert Comment

    that is a strange question :
    usually, someone wants to do something and asks how to do it and/or if some idea would serve the purpose.
    YOU have the desire to use some generic technique and are asking how you could use it with your application (2) and precisely which brand of this generic technique you should use (1).

    And of course, all that without telling us what your application is doing. There are dozens of dozens of API technology, usage, with pro and cons for each, without a single one better than all on all counts.
    LVL 3

    Expert Comment

    There are many possibilites. For example you can easy expand your application to Automation Server.

    Other possibility is moving required functionality to separate DLL and you can both use this DLL in your application and document DLL's function for use by external applications.
    LVL 21

    Expert Comment

    It will depend largely on the type of application it is.

      If you wrote something akin to MS Word then you would have a GUI application that would be limited in the type of API it could use (A web service would probably be out).  In this case I would probably go with a COM object.  This is coming from someone with many years of experience developing in Windows.  IF you need your application to be cross platform then the solution would likely become much more complicated.

      If the application is a web page, and you want developers to be able to use the functionality of the web site (without needing to use the web pages themselves), then you could easily base your web page on a web service type of API, allowing other developers to access it.

      If the application handles things in a background manner and you want other applications on the same machine (or across a network) to be able to access these pieces of functionality then a service may be what you are looking for (think SQL Server, or any database server, as an example of this type of functionality).

    I hope this helps you to quantify what we, as the experts trying to help, would need to understand of your project.

    Author Comment

    Ok, I will clarify this.

    I have many business softwares as stock softwares, ERP, CRM etc.

    Many people ask me how to connect other business softwares to my softwares. They ask if I can give them an Api specification so their softwares and my softwares can work together as "one".

    The idea is if 10 different softwares need to be connected to my software that I don't need to make 10 different contact points but only one which I give to the developers of other companies and they can connect no matter if the other is an invoice system ,a bidding system or a webshop.

    Thank you
    LVL 25

    Expert Comment

    What do you mean by connect :
    a - 'simple' data exchange (in ? out ?)
    b - or complex 'functions' calls of your software from others ?

    for a), what is your kind of data, do you use a database that can be queried ? maybe you could implement an XML bridge ?
    for b) maybe you could create WebServices API

    your explanations are better than nothing, but you really should detail the kind of relationship between your softwares and others

    Author Comment

    I need a: simple data exchange both in and out.
    I use different databases mostly MySql (but all of them can be queried)

    I don't know anything about XML bridge.
    LVL 21

    Expert Comment

     Normally I would do a web service for this type of thing.  If you need to allow other software to... log in... keep a list of stock symbols for their account... do a query to get a list of historic stock data... WHATEVER...  You can make the web service handle several individual calls to perform the various tasks.  Each web service call will have it's own parameters and results.  If you pass a user name and password to a web service (use https to encrypt it) then you could return a session ID that would be a required parameter to use any of the other web service calls.  This would enforce the software using your web service to log in for access.  If the other software makes a call to get a historic list of data for stocks, they would pass the session ID and... a parameter to specify which stocks (blank could be interpreted as all).  I would make the result of the call a string containing XML that could be used by the client software to create a dataset on their end to allow them to see the data.

      I say all of this as examples.  When you do a web service, there are many languages that can read the Web Service Description Language (WSDL) file to enable their code to call your web service.  Doing a web service means that your application would need to run on (or as) a web server.  If you do not want this to be part of your design, you could try to do it as a COM object and have the same functionality (limited to running on Windows).  If all programs accessing your data need to do so concurrently then it should be handled as a single central server (once again indicating something like a web service).  If it is handled as COM then it becomes a COM object running on a server that is accessed by other computers via DCOM.

      Delphi is capable of creating ISAPI DLLs that can be run on a web server.  There are, as the old adage goes, "many ways to skin a cat".  We still do not have much information to go on to help you define your user interface.  You need to determine 1) exactly what capabilities you want to expose 2) what platforms you want to support 3) what technologies you can use to meet those goals and 4) which technology you want to implement from the list.  There is no single right answer to this type of question.  My own experience tells me to let the needs define the implementation.  That is impossible to do without the list of needs...

    One more try at guiding you to the details required...
    LVL 25

    Accepted Solution

    You would use a WebService if you need/want your software to constantly run in a server, accessible from anywhere (TCP/IP). For ex. if your system is a CRM program that can track purchase from customers and emit some special offers, it has to be accessible by the retail software at any time.

    If your software only prepare data on a regular basis (either because it analyse data from other sources, or because data it generates can be used by other systems 'offline' and be only updated every day or week) , you would have to make a bridge. A bridge is quite simply a data importer/exporter. Most systems uses CSV files or XML files for data exchange. I, for once, have almost every month a project where some system must be coupled with another system (I work with retail systems). 90% is CSV file -based interface, because it's simple, effective, and any low level programmer can do it, so that's what's used by all big companies having a product to interface with anything from anyone.
    XML is convenient as a format because it can be hierarchical, and can be expanded easily.
    But believe it or not, it's far from perfect, it has some heaviness in the way it must be used, and often requires at least a bit of computer skills to handle properly. I have seen more badly designed XML interfaces than good ones, and while it can work, it's often at a higher cost than expected.

    Maybe first you should see what kind of data export can be done directly by your DBMS. I am confident that you have already everything to setup DB tables import/export with CSV and XML. The hard part does not rely in the importation/exportation of the raw data, but in the validation of the data you import in your system. Only you can tell what kind of constraints you have to check, and what to do with a batch of data having only one error (like a ref to a product that does not exist in your DB, in a single invoice... What to do with the 1000+ other good ones ? with the faulty one ?).
    A good bridge is capable of checking everything that should be, before actually importing it in the DB, and report in a consistent way errors to the user or the automated system using your bridge.
    It should not rely only on the DB constraints and not manage exceptions thrown by the DBMS, and quit with a single error 'Importation failed.' With 50Gb XML files, that is annoying, and good luck to find out that a misplaced space in a field is responsible for the whole thing failing... I'm talking about a real experience, with a badly designed XML bridge, from a big company that should have had the resources to do it right... (I'm not going to name it)

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
    Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now