Application API reason. What is an API? Simple explanation for beginners


In order to make the work of their colleagues easier and to provide all Windows programs with a universal interface, Microsoft programmers created such a thing as an API - "Application Programming Interface".

This is a set of functions and procedures that can be most often used by programs: displaying a directory tree, searching for files, displaying a standard window with close, minimize and maximize buttons, and many others. As a result, a developer creating a program for Windows does not have to think through and develop special subroutines for displaying the program window, the window for selecting a folder and other similar elementary operations - he can simply call kernel32.dll or user32.dll from the libraries containing functions and procedures API, the function he needs, and she will do everything for him herself. There are many such functions and procedures - about 600.

In the MS-DOS operating system there was no such thing as an API - the one who undertook to write a program for this operating system was obliged to think through and implement methods for displaying images on the screen, receiving data from the user, from start to finish. traveling through the file system, drawing graphics, if such a possibility was necessary 2. This made the process of developing programs with a user-friendly interface a very labor-intensive process; often the time and effort spent on creating an acceptable graphical interface for the program exceeded the costs of implementing the program’s own algorithm, for which it was created. It is not for nothing that so-called “console” applications were very common, that is, programs that worked only from the command line, without an interface - data was entered on the same command line or made from a file specified in it, and the results were output in simple text mode.

With the advent of the Windows operating system, the hard work of programmers to develop the appearance of the program and convenient methods for entering and outputting information was greatly facilitated - API functions were already used in Windows 3.0. Now a programmer, if, for example, he wanted to create a text input window or a scroll bar, he only had to write a call to the function for displaying such a window with the parameters he needed, just like any other function of the language in which he wrote his program, and not to introduce huge amounts of code to create a program that re-draws such a window or bar (while being aware that when developing the next program that also uses such objects, he will have to develop such code again or try to partially use the old one, adapting it to the needs this new program). Therefore, the emergence of the API made a revolutionary breakthrough in programming technology, allowing you to create the necessary programs with a familiar, convenient interface much faster, without worrying about such routine details as programming standard interface objects for input and output of information.

In the Visual Basic for Applications (VBA) language, many functions and API procedures are called themselves when the program is executed by the interpreter, so there is absolutely no need to use them to display text input and output windows, draw geometric shapes on the screen and other simple actions - VBA calls them as needed, and the program on it only needs to use the appropriate functions of this language. However, sometimes there is a need for certain actions for which either there are no analogues in the built-in VBA functions, or they work irrationally or too slowly. For example, a folder selection window with an image of a directory tree (Fig. 5.1) or a file search program (analogue in VBA functions - the "Application.FileSearch" object - works too slowly with large numbers of files). For such cases, VBA provides the ability to call API functions.

Unfortunately, the use of API functions in VBA is not documented in the help, so to learn how to use them you have to either look for books or online sources on office programming, or analyze the code of programs that contain calls to API functions.

In the vast majority of cases, when programming for Office, you can do without using the API, but sometimes just calling an API function can achieve the desired result. Let's say you need to ensure that different macros are called when you simply click a button on a Word toolbar with the mouse and when you simultaneously press this button and the Shift or Control key. Here's a snippet of code doing this:

Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal kState As Long) As Integer

GetAsyncKeyState(vbKeyShift Or vbKeyControl)

If GetAsyncKeyState(vbKeyShift) Then

Call macro1: Exit Sub

ElseIf GetAsyncKeyState(vbKeyControl) Then

Call macro2: Exit Sub

The first line is like “reserving” an API function for use in a VBA program. It can be seen that the GetAsyncKeyState function is called from the library (a file containing programs intended only for use by other programs) user32.dll, and the key number is passed to this function, and it returns an integer (namely 0, if the key with the corresponding number is not pressed, and -32767 or 1 if pressed). Any function or procedure called from non-VBA libraries must be so reserved using the Declare command.

The vbKeyShift phrase in the command is a substitute for the Shift key code (its value is 16), and vbKeyControl, as is easy to understand, is a substitute for the Control key code. The structure of the "If...Then" statements seems to be clear 3, but if not, look in the VBA help. The Call command before the macro name, as you remember, means launching it.

There are Russian sites on the Internet dedicated to API 4. Visit them to learn more about this feature set.

Definition: An application programming interface (API) is a description of a method that allows a piece of software to contact another program to obtain a service. This service may be providing access to data or performing a specific function. Interfaces are designed for most enterprise software and play a critical role in operating systems that control most basic computer functions.

Often we have to turn to other people with a request to do work that we cannot do on our own for one reason or another, for example, open a deposit box in a bank. Likewise, almost all software requires the use of other programs to perform certain functions. For this purpose, a set of standardized requests (called application programming interfaces) is used, defined for the program to which the request is addressed. Almost every application accesses the underlying operating system's API to perform basic functions such as file system access.

Essentially, a program's application interface defines the correct way a developer can use to call the services needed by a particular program. Developers can execute queries by adding calls to their application code. The syntax is described in the documentation of the called application.

By providing a means to request software services, an API guarantees access or the ability to open an application. According to Josh Walker, an analyst at Forrester Research, “Building an application without an API is like building a house without doors. For any computing task, an application programming interface opens the windows and doors for information exchange.”

In addition, application programming interfaces enable applications to communicate with each other. SAP's enterprise applications include an API called BAPI that allows other applications to access business data. When an industry standard for data is adopted, it usually follows with a single application programming interface that provides access to the applications that process that data.

Middleware acts as a standardized, analogous API that allows applications written for different platforms or in different languages ​​to communicate.

According to Adam Braunstein, an analyst at Robert Frances Group, while APIs provide a quick and convenient way to access an application, they can be too limited for users who require more capabilities, such as independent software vendors. Free software allows you to get the text of any command and operation in the application and thus provide greater flexibility. But it can take too much time to understand the source text, and in addition, this approach inevitably raises questions about the author's intellectual property.

When Novell announced last year that it would make the source code for its Novell Directory Services (NDS) software available to the general public, Chris Stone, then a Novell vice president, said that most enterprise developers were reluctant to dig into the code freely. distributed software. In fact, he says, developers want additional sets of APIs that will help them work faster. And to this day the source texts of NDS have not been published.

Enterprise developers must decide whether to include application interfaces in the applications they create. Over time, the likelihood that another developer will need to access the services of this application only increases. According to Braunstein, the creation of an API will relieve programmers who will subsequently work with this application from having to search for the necessary text and understand how the code works.

Application programming interfaces are easy to create, but as GartnerGroup analyst Larry Perlstein noted, they can be difficult to learn. Application developers and manufacturers must constantly think about whether their application programming interfaces will be understandable to subsequent developers. "An API is useless unless it's documented," Perlstein said, although some vendors leave their APIs undocumented.

API as a weapon against competitors

If a company wants to frustrate developers, it can keep its APIs secret or change them quickly. Many of Microsoft's critics, including government prosecutors and competitors, accuse the company of not shying away from such practices.

Andrew Shulman described several hidden APIs of the Windows operating system in his book Undocumented Windows. He now works as a consultant for Caldera, which is suing Microsoft for violating antitrust laws. Now, instead of hiding APIs, Shulman writes, “Windows has a kitchen-sink architecture that allows new application programming interfaces to be hidden. This?mixing? The API is an attempt to prevent Windows from being cloned."

Judge Thomas Penfield Jackson made similar arguments during a November 5 hearing in the Justice Department's case against Microsoft. He said that "trying to clone the 32-bit Windows API is so expensive and futile that it makes it nearly impossible for a Windows competitor to emerge."

But Perlstein noted that by criticizing the company for its methods of supporting the Windows API, Microsoft's competitors are giving vent to their envy at the expense of fairness. Microsoft spokesman Jim Cullinan says Microsoft is constantly improving Windows and updating and adding application programming interfaces, as slowing down the rate of modernization could result in missed release deadlines.

Application Programming Interfaces and You

Application Programming Interfaces (APIs) have a mysterious feel to them, and manufacturers or developers are eager to wave them around like magic wands that can solve all problems. But in reality, APIs can be very simple and powerful. Each of us uses something similar to an API in everyday life, when, for example, we ask someone for a service. APIs offer less flexibility than freely available code, but more flexibility than completely proprietary applications.

Imagine that you have three neighbors. Closed Zinovy, Open Oscar and API Ann. Each of them is an analogue of an application. Like any of your neighbors, sometimes you need to borrow something from them, such as a lawnmower. This is the equivalent of application integration.

Closed Zinovy it simply does not provide you with any services. He mows his own grass behind the high fence that surrounds his house. Not only are you unable to ask him for anything, but you can't even go into his yard to try to talk because his fence doesn't have a gate. An application such as Closed Zinovy ​​does not provide either source code or an application programming interface.

Open Oscar- the complete opposite of him. He is so open that he allows you to freely enter his yard whenever you want and even repair his mower, so he is very responsive to your requests. Of course, once you change the design of the lawnmower described in the manual, you will have to deal with its own repairs and maintenance. Apps like Open Oscar are open source which allows you to customize it however you want.

API Anna will allow you to use her lawnmower if you ask her to do so correctly (by calling the "daikomower" API in the body of your application). You cannot enter the gate without such a request and you cannot turn on the lawnmower and cut the grass. But you can use this service (lawn mowing) any time you want. Most often, enterprises use applications that are closed but have an API, like Anna.

Leonid Yakubovich November 26, 2012 at 01:59 pm

What is an API

  • Lumber room *

Greetings!
In this article we will look at what an API is, where, how and for what it is used. We will also look at how the API can be used in your web developments and how it can simplify the life of a web programmer.

So let's start with the definition. API (Application Programming Interface) is a programming interface, an interface for creating applications. In more understandable terms, an API is ready-made code to make a programmer’s life easier. The API was created so that a programmer could actually make the task of writing an application easier by using ready-made code (for example, functions). The well-known jQuery, written in JavaScript, is also a kind of API. If we look at this example specifically, jQuery makes writing code much easier. What could be done using regular JavaScript tools in 30 lines is written in 5-6 using jQuery. If we look at APIs in general, we can find a lot of services that provide development solutions. The most famous today is the code.google.com service, which provides about fifty different APIs! This includes an interface for creating Android applications, various APIs for working with AJAX, and various application APIs that can be easily customized to your liking.

After all, does it make sense to write code yourself? Why work on what has already been created? Does it make sense to refuse free solutions (and in fact, free help) in web development? If you answered “NO” to all these questions, then consider that you understand the essence of the API.

But I also want to make a reservation. Beginner developers should NOT use half-baked solutions, as they will not cope with the real problem in the future. Therefore, if you are a beginner web programmer, then do not use semi-finished products! Learn to think with your own head, build various algorithms to understand the essence of programming. I also say, already addressing everyone, that APIs are not ready-made solutions, they are an environment, an interface for creating your own projects. You don't eat frozen cutlets from the store, do you? You fry them first, right? This analogy captures the essence of the API very clearly.

In general, I told you what an API is, where and how it is used, and most importantly, why. I wish you a pleasant learning of web programming and understanding its ever greater depths!

Let's start with the basics: what is an API? The abbreviation stands for Application Programming Interface, or interface for application programming. The name seems to speak for itself, but it’s better to consider a more detailed explanation.

As already mentioned, an API is, first of all, an interface. An interface that allows developers to use ready-made blocks to build an application. In the case of developing mobile applications, a library for working with a smart home can act as an API - all the nuances are implemented in the library and you only access this API in your code.

In the case of web applications, the API can return data in a format other than standard HTML, making it convenient to use when writing your own applications. Third-party public APIs most often serve data in one of two formats: XML or JSON. In case you decide to make an API for your application, remember that JSON is much more concise and easier to read than XML, and services that provide access to data in XML format are gradually abandoning the latter.

API in web applications with examples

An application - for example, Github - has its own API that other developers can use. How they will use it depends on the capabilities that the API provides and on how well the developers’ imagination works. The GitHub API allows, for example, to obtain information about the user, his avatar, readers, repositories and many other useful and interesting information.

In a similar way, you can send a request in any language, including Ruby. The response to the request will be approximately the following information:

( "login" : "Freika" , "id" : 3738638, "avatar_url" : "https://avatars.githubusercontent.com/u/3738638?v=3", "gravatar_id" : "" , "url" : "https://api.github.com/users/Freika", "html_url" : "https://github.com/Freika" , "followers_url" : "https://api.github.com/users/Freika/followers", "following_url" : "https://api.github.com/users/Freika/following(/other_user)", "gists_url" : "https://api.github.com/users/Freika/gists(/gist_id)", "starred_url" : "https://api.github.com/users/Freika/starred(/owner)(/repo)", "subscriptions_url" : "https://api.github.com/users/Freika/subscriptions", "organizations_url" : "https://api.github.com/users/Freika/orgs", "repos_url" : "https://api.github.com/users/Freika/repos", "events_url" : "https://api.github.com/users/Freika/events(/privacy)", "received_events_url" : "https://api.github.com/users/Freika/received_events", "type" : "User" , "site_admin" : false , "name" : "Evgeniy" , "company" : "" , "blog" : "http://frey.su/" , "location" : " Barnaul" , "email" : "" , "hireable" : true , "bio" : null, "public_repos" : 39, "public_gists" : 13, "followers" : 15, "following" : 21, "created_at" : "2013-03-01T13:48:52Z" , "updated_at" : "2014-12-15T13:55:03Z" )

As can be seen from the block above, the response contains the login, avatar, link to the profile on the site and in the API, user status, number of public repositories and other useful and interesting information.

API alone is not enough

Creating a full-fledged API for your application is only half the battle. How are you supposed to access the API? How will your users access it?

The first thing that comes to mind is the usual series of HTTP requests to obtain the desired information, and this is the wrong answer. The most obvious method in this case is not the most convenient and simple. It would be much more reasonable to create a special library for working with the interface, which will describe all the necessary ways to receive and send information using the API.

Let’s use Github once again to give an example: to work with the API of this excellent service (and its interface provides extensive capabilities), several libraries have been created in various languages, for example the Octokit gem. In the documentation for such libraries (and the gem given as an example), any interested developer will be able to find all the necessary ways to receive information from Github and send it back through the service API.

Thus, if you are creating your own API, consider perhaps creating libraries to work with it in the most common languages. And be prepared that at a certain level of demand for your application, someone else may create their own library to work with your API. This is fine.

useful links

In subsequent articles we will talk about how to correctly create an API, ensure its security and limit access to some information.

API (from the English Application Program Interface) is an interface for interaction between the client’s website and the server. Represents a resource that the server opens for work from the outside, i.e. a programmer can use it to gain access to the functionality of a program, library, or module. The API makes it possible to operate resources that use the potential and power of the providing site, as well as launch additional components to them that expand the capabilities of the web project.

Advantages:

Types

  • returning. When a third-party application requests a method with specified parameters, the server provides the requested information in a specific format;
  • changing. The client calls some server function that enters new information or changes certain settings on it.

Yandex.Direct API

API is effective for website promotion.

  1. Based on it, developers can create applications that directly interact with the search engine service. Such programs will allow advertisers to flexibly manage large-scale advertising, receive statistical reports on each of them, and accurately forecast budgets.
  2. Using the Direct API, advertising agencies can view the entire list of their clients, and clients can view their representatives.
  3. If certain phrases used for search engine optimization give a low CTR in contextual advertising, display for them can be automatically disabled. On thematic platforms, you can set rates via the API; certain donors can be removed.
  4. The Yandex.Direct API has a SOAP interface, that is, it provides a wide selection of programming languages ​​for creating applications. This protocol is supported by languages ​​such as Perl, Java,






2024 gtavrl.ru.