We no longer live in a world of computer programs or even standalone web applications, but of services. Different systems expose them so that others can communicate with them and use their data (in an authorized way, of course) in external applications as well. A very large part of today's software is built on this mechanism: it integrates with other software, lets information flow from every corner of the Internet, and in this way extends its reach and the owner's profits.

It is natural that all of us want our system to be widely used and "integrable" with other applications. At this point some people remember that they have heard of something called an API and ask the software house whether they can have one in their portal too. Sometimes, as an IT company, we even hear from clients "we want an API, how long will you need?" That is why in this text I want to explain what such an API actually is and why you need to think through what it is supposed to be for.

What is an API, anyway?

First, a short encyclopedic note: API is short for Application Programming Interface and means an interface to an application (or a computer system), but not a graphical one for ordinary users, rather one for developers. It is usually used to integrate external software with our system or to access its resources. An API can take various forms, and originally it was understood as an exposed library, an SDK or simply code to include in your own programs. Today, however, we mostly talk about APIs in the context of web services, and in this article we will take only that meaning.

An API is as friendly to developers as a graphical interface (UI) is convenient for users doing the usual "clicking". In theory you can integrate through the UI, but that is very unwise and used only as a last resort. That is why access methods, ideally documented ones, are a lifesaver in integrations.

What are web services and REST?

Let us now say what these web services I have already mentioned are. You could say they are special web addresses, so-called endpoints (literally "end points", although "entry points" fits better here), where data or operations on data are exposed. Depending on the specific address and the type of request, different actions are possible, such as retrieving information or inserting objects. Sometimes they also serve as separate functions for various specialized tasks that we do not want to write ourselves. Here is an example: the API of the SendGrid email sending service.

Very often, when people talk about web APIs, they mean a REST API, and I think it is worth stating this explicitly in conversations, to be sure both sides understand the communication the same way. REST is one of the protocols for using web services, based on plain HTTP requests, which makes it very simple and usable in practically every case. It really dominates the world of web APIs, and only recently has a solution called GraphQL begun, rather timidly, to break through. The SOAP protocol used to be common, but because of its complexity it is better to focus on REST.

Why might I need an API?

I have already mentioned that APIs are used to integrate different services with each other, also to make your own system more attractive. Let us look at two examples.

1. We build a service that provides currency exchange rates, and we want various developers to be able to use the values we collect in their applications. For that we create an API that makes it possible to fetch the rates (by various criteria) and publish it together with documentation. This way we do the community a service, and we can also "package" it in business terms in different ways (for example, by setting limits for users of a free account to encourage them to buy a premium account).

2. We build a system that helps plan trips, and one of the requirements is to show the current weather in a place chosen by the user. We do not want to collect weather data ourselves, because there are various APIs that can help. We pick a service that suits us, read the terms of use (and the limits or costs) and use the services it exposes.

As you can see, the value of using APIs comes mainly from connecting different services with each other, but that is not all. It is also worth noting that most web applications use their own API for normal operation too. Software is usually split into frontend and backend, and the former talks to the latter precisely through an API. In more complex applications this also makes it easier to split the backend into many services (even microservices) that exchange data with each other, among other ways, through web services.

As you can see, building an API makes sense from an architecture point of view, and exposing it can also bring business benefits. So you could say it is worth planning it from the start and including it in the assumptions of the application.

What should I do when I need an API?

And here we get to the question from the introduction: "we want an API, how long will you need?" Well, we have to realize a few things here.

If there is even a shadow of a chance that such an interface for developers will be needed in the future, it is worth saying so at the earliest possible stage. Very often it pays off to base the whole architecture of the application on an API, which at least reduces the effort of later development work. This matters because such services also need proper security and a permission mechanism, and if we plan to write code with this subsystem in mind, we should do it as early as possible. Besides, most current web applications, apart from very specific ones (for example, for a company's internal use), practically all transfer data this way.

You can also add an API to an application that is not built around such communication. It depends on the technology, but it is usually possible (which does not mean it is always convenient), and as a last resort you can try a second backend exposed as a separate interface. Apart from the technical matters, you need to consider the cost of introducing such a solution into the project from an organizational point of view.

The most important thing, though, is still defining what exactly the API is supposed to do. No software house or freelancer can even try to estimate the cost of building the services without knowing the scope of access methods that the system should offer through the interface for developers. Of course, the more detailed the instructions, the better, but before coding starts it is essential to settle the context of the work and the capabilities the API will offer. Apart from its functionality, other criteria also need to be agreed: whether it will be a public API, what data will be needed for authorization, which protocol will be supported, and what limits we plan for users.

Summary

Systems that expose an API are by now so common on the web that the term comes up even in conversations outside IT, and no wonder that everyone wants (or needs) their software to offer such an interface. That does not mean it should be done without a plan: at the start you need to think through what your goal is in creating such an environment and who it will be aimed at. It is also worth including the API in your plans as early as possible, or at least letting the IT company know whether it will be needed in the future.

Best regards, and thank you. Jakub Rojek.