In [[computer programming]], an '''application programming interface''' ('''API''') is a set of [[subroutine]] definitions, [[wiktionary:Protocol|protocols]], and tools for building [[application software]]. In general terms, it is a set of clearly defined methods of communication between various software components. A good API makes it easier to develop a [[computer program]] by providing all the building blocks, which are then put together by the [[programmer]].
An API may be for a web-based system, [[operating system]], [[database system]], [[computer hardware]] or [[Library (computing)|software library]].
An API specification can take many forms, but often includes specifications for [[subroutine|routines]], [[data structure]]s, [[Class (computer programming)|object classes]], [[variable (computer science)|variable]]s or [[Remote procedure call|remote calls]]. [[POSIX]], [[Microsoft]] [[Windows API]], the [[C++]] [[Standard Template Library]] and [[List of Java APIs|Java API]]s are examples of different forms of APIs.
Documentation for the API is usually provided to facilitate usage.
== Purpose ==
Just as a [[graphical user interface]] makes it easier for people to use programs, application programming interfaces make it easier for [[Software developer|developers]] to use certain technologies in building applications.
By [[Abstraction (software engineering)|abstracting]] the underlying implementation and only exposing objects or actions the developer needs, an API simplifies programming. While a graphical interface for an [[email client]] might provide a user with a button that performs all the steps for fetching and highlighting new emails, an API for file [[input/output]] might give the developer a [[Subroutine|function]] that copies a file from one ___location to another without requiring that the developer understand the [[Journaling file system|file system]] operations occurring behind the scenes.<ref name="Clarke4">{{cite web|last1=Clarke|first1=Steven|title=Measuring API Usability|url=http://www.drdobbs.com/windows/measuring-api-usability/184405654|website=Dr. Dobb's|accessdate=29 July 2016|date=2004}}</ref>
== Uses ==
===Libraries and frameworks===
An API is usually related to a [[library (computing)|software library]]. The API describes and prescribes the ''expected behavior'' (a specification) while the library is an ''actual implementation'' of this set of rules.
A single API can have multiple implementations (or none, being abstract) in the form of different libraries that share the same programming interface.
The separation of the API from its implementation can allow programs written in one language to use a library written in another.
For example, because [[Scala (programming language)|Scala]] and [[Java (programming language)|Java]] compile to compatible [[bytecode]], Scala developers can take advantage of any Java API.<ref name="OderskySpoonVenners8">{{cite web|last1=Odersky|first1=Martin|last2=Spoon|first2=Lex|last3=Venners|first3=Bill|title=Combining Scala and Java|url=http://www.artima.com/pins1ed/combining-scala-and-java.html|website=www.artima.com|accessdate=29 July 2016|date=10 December 2008}}</ref>
API use can vary depending on the type of programming language involved.
An API for a [[procedural programming|procedural language]] such as [[Lua (programming language)|Lua]] could primarily consist of basic routines to execute code, manipulate data or handle errors, while an API for an [[object-oriented programming|object-oriented language]] such as [[Java (programming language)|Java]] would provide a specification of classes and their [[class method]]s.<ref>{{cite journal|last1=de Figueiredo|first1=Luiz Henrique|last2=Ierusalimschy|first2=Roberto|last3=Filho|first3=Waldemar Celes|title=The design and implementation of a language for extending applications|journal=TeCGraf Grupo de Tecnologia em Computacao Grafica|url=https://www.researchgate.net/profile/Waldemar_Celes/publication/2778436_The_Design_and_Implementation_of_a_Language_for_Extending_Applications/links/00b7d522f51ad361f9000000.pdf|accessdate=29 July 2016}}</ref><ref name="Sintes16">{{cite web|last1=Sintes|first1=Tony|title=Just what is the Java API anyway?|url=http://www.javaworld.com/article/2077392/java-se/just-what-is-the-java-api-anyway.html|website=JavaWorld|accessdate=29 July 2016}}</ref>
[[Language binding]]s are also APIs. By mapping the features and capabilities of one language to an interface implemented in another language, a language binding allows a library or service written in one language to be used when developing in another language.<ref name=Emery>{{cite web|url=http://www.acm.org/tsc/apis.html |last1=Emery|first1=David|title=Standards, APIs, Interfaces and Bindings |publisher=Acm.org |date= |accessdate=2016-08-08}}</ref><ref name=cairo>{{cite web|url=http://www.cairographics.org/manual/language-bindings.html |title=Appendix A. Creating a language binding for cairo |publisher=Cairographics.org |date= |accessdate=2016-08-08}}</ref>
Tools such as [[SWIG]] and F2PY, a [[Fortran]]-to-[[Python (programming language)|Python]] interface generator, facilitate the creation of such interfaces.<ref>{{cite web|url=http://www.f2py.org/ |title=F2PY.org |publisher=F2PY.org |accessdate=2011-12-18}}</ref>
An API can also be related to a [[Framework (computer science)|software framework]]: a framework can be based on several libraries implementing several APIs, but unlike the normal use of an API, the access to the behavior built into the framework is mediated by extending its content with new classes plugged into the framework itself.
Moreover, the overall program flow of control can be out of the control of the caller and in the hands of the framework via [[inversion of control]] or a similar mechanism.<ref>{{cite web
An API can specify the interface between an application and the [[operating system]].<ref name="Oreilly91">{{cite book|last1=Lewine|first1=Donald A.|title=POSIX Programmer's Guide|date=1991|publisher=O'Reilly & Associates, Inc.|page=1|url=ftp://gamma.sbin.org/pub/doc/books/OReilly_-_POSIX_Programmers_Guide.pdf|accessdate=2 August 2016}}</ref>
[[POSIX]], for example, specifies a set of common APIs that aim to enable an application written for a POSIX conformant operating system to be [[Compiler|compiled]] for another POSIX conformant operating system.
[[Linux]] and [[Berkeley Software Distribution]] are examples of operating systems that implement the POSIX APIs.<ref name="WestDedrick16">{{cite journal|last1=West|first1=Joel|last2=Dedrick|first2=Jason|title=Open source standardization: the rise of Linux in the network era|journal=Knowledge, Technology & Policy|date=2001|volume=14|issue=2|pages=88–112|url=http://www.joelwest.org/Papers/WestDedrick2001b.pdf|accessdate=2 August 2016|publisher=Springer}}</ref>
[[Microsoft]] has shown a strong commitment to a backward-compatible API, particularly within their [[Windows API]] (Win32) library, so older applications may run on newer versions of Windows using an executable-specific setting called "Compatibility Mode".<ref>
An API differs from an [[application binary interface]] (ABI) in that an API is source code based while an ABI is [[Binary file|binary]] based. For instance, [[POSIX]] provides APIs, while the [[Linux Standard Base]] provides an ABI.<ref>{{cite web|
Remote APIs allow developers to manipulate remote resources through [[Communications protocol|protocol]]s, specific standards for communication that allow different technologies to work together, regardless of language or platform.
For example, the Java Database Connectivity API allows developers to query many different types of [[database]]s with the same set of functions, while the [[Java remote method invocation]] API uses the [[Java Remote Method Protocol]] to allow [[Remote procedure call|invocation]] of functions that operate remotely, but appear local to the developer.<ref name="Bierhoff9">{{cite journal|last1=Bierhoff|first1=Kevin|title=API Protocol Compliance in Object-Oriented Software|journal=CMU Institute for Software Research|date=23 April 2009|url=https://www.cs.cmu.edu/~kbierhof/thesis/bierhoff-thesis.pdf|accessdate=29 July 2016}}</ref><ref name="Wilson16">{{cite web|last1=Wilson|first1=M. Jeff|title=Get smart with proxies and RMI|url=http://www.javaworld.com/javaworld/jw-11-2000/jw-1110-smartproxy.html|website=JavaWorld|accessdate=29 July 2016}}</ref>
Therefore, remote APIs are useful in maintaining the object abstraction in [[object-oriented programming]]; a method call, executed locally on a proxy object, invokes the corresponding method on the remote object, using the remoting protocol, and acquires the result to be used locally as return value.
A modification on the proxy object will also result in a corresponding modification on the remote object.<ref name="AdvancedCorba">{{cite web
Web APIs are the defined interfaces through which interactions happen between an enterprise and applications that use its assets. An API approach is an architectural approach that revolves around providing programmable interfaces to a set of services to different applications serving different types of consumers.<ref>{{cite web |url=http://www.hcltech.com/sites/default/files/apis_for_dsi.pdf |website=www.hcltech.com |format=PDF download |title=API-fication |date=August 2014}}</ref>
When used in the context of [[web development]], an API is typically defined as a set of [[Hypertext Transfer Protocol]] (HTTP) request messages, along with a definition of the structure of response messages, which is usually in an Extensible Markup Language ([[XML]]) or JavaScript Object Notation ([[JSON]]) format. An example might be a shipping company API that can be added to an eCommerce-focused web site, to facilitate ordering shipping services and automatically include current shipping rates, without the site developer having to enter the shipper's rate table into a web database. While "web API" historically has been virtually synonymous for [[web service]], the recent trend (so-called [[Web 2.0]]) has been moving away from Simple Object Access Protocol ([[SOAP]]) based web services and [[service-oriented architecture]] (SOA) towards more direct [[representational state transfer]] (REST) style [[web resource]]s and [[resource-oriented architecture]] (ROA).<ref>
{{cite web
|first = Djamal
|last = Benslimane
|author2=Schahram Dustdar |author3=Amit Sheth
|title = Services Mashups: The New Generation of Web Applications
|publisher = Institute of Electrical and Electronics Engineers
|pages = 13–15
|year = 2008
}}
</ref> Part of this trend is related to the [[Semantic Web]] movement toward [[Resource Description Framework]] (RDF), a concept to promote web-based [[ontology engineering]] technologies. Web APIs allow the combination of multiple APIs into new applications known as [[mashup (web application hybrid)|mashup]]s.<ref>
In the social media space, web APIs have allowed web communities to facilitate sharing content and data between communities and applications. In this way, content that is created in one place can be dynamically posted and updated in multiple locations on the web.<ref name="Parr16">{{cite web|last1=Parr|first1=Ben|title=The Evolution of the Social Media API|url=http://mashable.com/2009/05/21/social-media-api/#1LJkofEl.Gqi|website=Mashable|accessdate=26 July 2016}}
</ref>
==Design==
The design of an API has significant impact on its usability.<ref name="Clarke4"/> The principle of [[information hiding]] describes the role of programming interfaces as enabling [[modular programming]] by hiding the implementation details of the modules so that users of modules need not understand the complexities inside the modules.<ref name="Parnas72">{{cite journal|last1=Parnas|first1=D.L.|title=On the Criteria To Be Used in Decomposing Systems into Modules|journal=Association for Computing Machinery|date=1972|url=http://www.cs.umd.edu/class/spring2003/cmsc838p/Design/criteria.pdf|accessdate=8 August 2016}}</ref> Thus, the design of an API attempts to provide only the tools a user would expect.<ref name="Clarke4"/> The design of programming interfaces represents an important part of [[software architecture]], the organization of a complex piece of software.<ref name="GarlanShaw94">{{cite journal|last1=Garlan|first1=David|last2=Shaw|first2=Mary|title=An Introduction to Software Architecture|journal=Advances in Software Engineering and Knowledge Engineering|date=January 1994|volume=1|url=http://www.cs.cmu.edu/afs/cs/project/able/ftp/intro_softarch/intro_softarch.pdf|accessdate=8 August 2016}}</ref>
Several authors have created recommendations for how to design APIs, such as [[Joshua Bloch]],<ref>{{cite web
| last = Bloch
| first = Josh
| title = How to design a good API and why it matters
| url = http://static.googleusercontent.com/media/research.google.com/en//pubs/archive/32713.pdf}}</ref> Kin Lane,<ref>{{Cite web|url=http://pages.3scale.net/rs/516-GHI-083/images/api-provider-guide-api-design.pdf|title=The Industry Guide to API Design|last=Lane|first=Kin|date=2016-03-14|website=|publisher=Kin Lane via 3scale|access-date=2016-03-14}}</ref> and Michi Henning.<ref>{{cite web
APIs are one of the most common ways technology companies integrate with each other. Those that provide and use APIs are considered as being members of a business ecosystem.<ref>{{cite web|
last=de Ternay|
first=Guerric|
title=Business Ecosystem: Creating an Economic Moat|
url=http://boostcompanies.com/business-ecosystem|
website=BoostCompanies|
date=Oct 10, 2015|
accessdate=2016-02-01}}</ref>
The main policies for releasing an API are:<ref name="Boyd16">{{cite web|last1=Boyd|first1=Mark|title=Private, Partner or Public: Which API Strategy Is Best For Business?|url=http://www.programmableweb.com/news/private-partner-or-public-which-api-strategy-best-business/2014/02/21|website=ProgrammableWeb|accessdate=2 August 2016}}</ref>
* Private: The API is for internal company use only.
* Partner: Only specific business partners can use the API. For example, [[Transportation network company|car service companies]] such as [[Uber (company)|Uber]] and [[Lyft]] allow approved third party developers to directly order rides from within their apps. This allows the companies to exercise quality control by curating which apps have access to the API, and provides them with an additional revenue stream.<ref name="Weissbrot16">{{cite web|last1=Weissbrot|first1=Alison|title=Car Service APIs Are Everywhere, But What’s In It For Partner Apps? {{!}} AdExchanger|url=http://adexchanger.com/mobile/car-service-apis-everywhere-whats-partner-apps/|website=ad exchanger|accessdate=2 August 2016|date=7 July 2016}}</ref>
* Public: The API is available for use by the public. For example, [[Microsoft]] makes the [[Microsoft Windows]] API public, and [[Apple Inc.|Apple]] releases its APIs [[Carbon (API)|Carbon]] and [[Cocoa (API)|Cocoa]], so that software can be written for their [[Computing platform|platforms]].
===Public API implications===
An important factor when an API becomes public is its ''interface stability''. Changes by a developer to a part of it—for example adding new parameters to a function call—could break compatibility with clients that depend on that API.<ref>{{cite journal|last1=Shi|first1=Lin|last2=Zhong|first2=Hao|last3=Xie|first3=Tao|last4=Li|first4=Mingshu|title=An Empirical Study on Evolution of API Documentation|journal=International Conference on Fundamental Approaches to Software Engineering|date=2011|url=https://www.researchgate.net/profile/Lin_Shi6/publication/225147411_An_Empirical_Study_on_Evolution_of_API_Documentation/links/0fcfd5090639809380000000.pdf|accessdate=22 July 2016|publisher=Springer Berlin Heidelberg}}</ref>
When parts of a publicly presented API are subject to change and thus not stable, such parts of a particular API should be explicitly documented as ''unstable''. For example, in the [[Google Guava]] library the parts that are considered unstable, and that might change in the near future, are marked with the [[Java annotation]] <code>@Beta</code>.<ref>{{cite web|url=https://code.google.com/p/guava-libraries/ |title=guava-libraries - Guava: Google Core Libraries for Java 1.6+ - Google Project Hosting |publisher=Code.google.com |date=2014-02-04 |accessdate=2014-02-11}}</ref>
A public API can sometimes declare parts of itself as ''[[Deprecation|deprecated]]''. This usually means that such part of an API should be considered candidates for being removed, or modified in a backward incompatible way. Therefore, deprecation allows developers to transition away from parts of the API that will be removed or unsupported in the future.<ref name="OracleDeprecation16">{{cite web|last1=Oracle|title=How and When to Deprecate APIs|url=http://docs.oracle.com/javase/7/docs/technotes/guides/javadoc/deprecation/deprecation.html|website=Java SE Documentation|accessdate=2 August 2016}}</ref>
==Documentation==
API documentation describes what services an API offers and how to use those services, aiming to cover everything a client would need to know to use the API.
Documentation is crucial for the development and maintenance of applications that use the API.<ref name="DekelHerbsleb9">{{cite journal|last1=Dekel|first1=Uri|last2=Herbsleb|first2=James D.|title=Improving API Documentation Usability with Knowledge Pushing|journal=Institute for Software Research, School of Computer Science|date=May 2009|url=http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.446.4214&rep=rep1&type=pdf|accessdate=22 July 2016|publisher=Carnegie Mellon University}}</ref>
API documentation is traditionally found in documentation files, but can also be found in social media such as blogs, forums, and Q&A websites.<ref name="ParninTreude11">{{cite journal|last1=Parnin |first1=Chris |last2=Treude |first2=Cristoph |title=Measuring API Documentation on the Web |journal=Web2SE |date=May 2011 |url=http://chrisparnin.me/pdf/parnin-webapi.pdf |accessdate=22 July 2016 }}{{dead link|date=July 2017 |bot=InternetArchiveBot |fix-attempted=yes }}</ref>
Traditional documentation files are often presented via a documentation system, such as [[Javadoc]] or [[Pydoc]], that has a consistent appearance and structure.
However, the types of content included in the documentation differs from API to API.<ref name="MaalejRobillard12">{{cite journal|last1=Maalej|first1=Waleed|last2=Robillard|first2=Martin P.|title=Patterns of Knowledge in API Reference Documentation|journal=IEEE TRANSACTIONS ON SOFTWARE ENGINEERING|date=April 2012|url=https://mobis.informatik.uni-hamburg.de/wp-content/uploads/2013/03/TSE-2012-04-0081.R2_Maalej.pdf|accessdate=22 July 2016}}</ref>
To facilitate understanding, API documentation can include description of classes and methods in the API as well as "typical usage scenarios, code snippets, design rationales, performance discussions, and contracts", but implementation details of the API services themselves are usually omitted.
Restrictions and limitations on how the API can be used are also covered by the documentation.
For example, documentation for an API function could note that its parameters cannot be null, or that the function itself is not [[Thread safety|thread safe]].<ref name="MonperrusEichberg11">{{cite journal|last1=Monperrus|first1=Martin|last2=Eichberg|first2=Michael|last3=Tekes|first3=Elif|last4=Mezini|first4=Mira|title=What should developers be aware of? An empirical study on the directives of API documentation|journal=Empirical Software Engineering|date=3 December 2011|volume=17|issue=6|pages=703–737|doi=10.1007/s10664-011-9186-4|url=http://arxiv.org/pdf/1205.6363.pdf|accessdate=22 July 2016}}</ref>
Because API documentation is so comprehensive, it can be difficult for the writers to keep the documentation updated and for the users to read it carefully, potentially resulting in [[Software bug|bugs]].<ref>{{cite journal|last1=Shi|first1=Lin|last2=Zhong|first2=Hao|last3=Xie|first3=Tao|last4=Li|first4=Mingshu|title=An Empirical Study on Evolution of API Documentation|journal=International Conference on Fundamental Approaches to Software Engineering|date=2011|url=https://www.researchgate.net/profile/Lin_Shi6/publication/225147411_An_Empirical_Study_on_Evolution_of_API_Documentation/links/0fcfd5090639809380000000.pdf|accessdate=22 July 2016|publisher=Springer Berlin Heidelberg}}</ref>
API documentation can be enriched with [[metadata]] information like [[Java annotation]]s. This metadata can be used by the compiler, tools, and by the ''run-time'' environment to implement custom behaviors or custom handling.<ref>{{cite web|url = http://download.oracle.com/javase/1,5.0/docs/guide/language/annotations.html|title = Annotations|accessdate = 2011-09-30|publisher = [[Sun Microsystems]]}}.</ref>
==Copyright controversy==
{{Main article|Oracle America, Inc. v. Google, Inc.}}
In 2010, [[Oracle Corporation]] sued [[Google]] for having distributed a new implementation of [[Java (programming language)|Java]] embedded in the [[Android (operating system)|Android]] operating system.<ref>{{cite web|url=http://www.drdobbs.com/jvm/232901227 |title=Oracle and the End of Programming As We Know It |publisher=DrDobbs |date=2012-05-01 |accessdate=2012-05-09}}</ref> Google had not acquired any permission to reproduce the Java API, although permission had been given to the similar [[OpenJDK]] project. Judge [[William Alsup]] ruled in the ''[[Oracle v. Google]]'' case that APIs cannot be [[copyrighted]] in the U.S, and that a victory for Oracle would have widely expanded copyright protection and allowed the copyrighting of simple software commands:
<blockquote>To accept Oracle's claim would be to allow anyone to copyright one version of code to carry out a system of commands and thereby bar all others from writing their own different versions to carry out all or part of the same commands.<ref>{{cite web|url=http://www.tgdaily.com/business-and-law-features/63756-apis-cant-be-copyrighted-says-judge-in-oracle-case |title=APIs Can't be Copyrighted Says Judge in Oracle Case |publisher=TGDaily |date=2012-06-01 |accessdate=2012-12-06}}</ref><ref>{{cite web
In 2014, however, Alsup's ruling was overturned on appeal, though the question of whether such use of APIs constitutes [[fair use]] was left unresolved.<ref>{{cite news | url=http://www.cnet.com/news/court-sides-with-oracle-over-android-in-java-patent-appeal/ | title=Court sides with Oracle over Android in Java patent appeal | work=CNET | date=May 9, 2014 | accessdate=2014-05-10 | author=Rosenblatt, Seth}}</ref>
In 2016, following a two-week trial, a jury determined that Google's reimplementation of the Java API constituted fair use, but Oracle vowed to appeal the decision.<ref>{{Cite web|url=https://arstechnica.com/tech-policy/2016/05/google-wins-trial-against-oracle-as-jury-finds-android-is-fair-use/|title=Google beats Oracle—Android makes "fair use" of Java APIs|website=Ars Technica|access-date=2016-07-28}}</ref>
* [[Advanced SCSI programming interface|ASPI]] for [[SCSI]] device interfacing
* [[Cocoa (API)|Cocoa]] and [[Carbon (API)|Carbon]] for the [[Macintosh]]
* [[DirectX]] for [[Microsoft Windows]]
* [[EHLLAPI]]
* [[List of Java APIs|Java APIs]]
* [[Open Database Connectivity|ODBC]] for [[Microsoft Windows]]
* [[OpenAL]] cross-platform sound API
* [[OpenCL]] cross-platform API for general-purpose computing for CPUs & GPUs
* [[OpenGL]] cross-platform graphics API
* [[OpenMP]] API that supports multi-platform shared memory multiprocessing programming in C, C++ and Fortran on many architectures, including Unix and Microsoft Windows platforms.
* {{cite journal |url= http://computationalculture.net/article/objects-of-intense-feeling-the-case-of-the-twitter-api |journal=Computational Culture |year=2013 |author= Taina Bucher |title= Objects of Intense Feeling: The Case of the Twitter API |number=3 |issn=2047-2390 }} argues that "APIs are far from neutral tools" and form a key part of contemporary programming, understood as a fundamental part of culture.