API: Difference between revisions

Content deleted Content added
Unnecessary words (in QCon talk by "Joshua Bloch")
windows
Tags: references removed Visual edit Mobile edit Mobile web edit
Line 1:
{{redirect|API}}
 
In [[ProgrammingComputer languageprogramming optimization|computer programming]], an '''application programming interface''' ('''API''') is a set of subroutine definitions, [[wiktionary:Protocol|protocols]], and tools for building software. In general terms, it is a set of clearly defined methods of '''communication''' between various 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]], [[Windows API]] and [[Advanced SCSI programming interface|ASPI]] are examples of different forms of APIs. Documentation for the API is usually provided to facilitate usage and implementation.
 
== Purpose ==
Just as a [[graphical user interface]] makes it easier for people to use programs, application programming interfaces make it easier for [https://www.code-brew.com/services/mobile-app-development/ 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]]smethods.<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]]sbindings 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>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 by [[inversion of control]] or a similar mechanism.<ref>{{cite web
|first = Martin
|last = Fowler
|title = Inversion Of Control
|url = http://martinfowler.com/bliki/InversionOfControl.html
}}
</ref><ref>{{cite web
|first = Mohamed
|last = Fayad
|title = Object-Oriented Application Frameworks
|url = http://www.dre.vanderbilt.edu/~schmidt/CACM-frameworks.html
}}
</ref>
 
===Operating systems===
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>
{{cite web
|author=Microsogt
Line 87 ⟶ 75:
{{Main article|Web API}}
Web APIs are the defined interfaces through which interactions happen between an enterprise and applications that use its assets, which also is a Service Level Agreement (SLA) to specify the functional provider and expose the service path or URL for its API users, An API approach is an architectural approach that revolves around providing a program interface 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 a set of specifications , such as [[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 website, 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
Line 114 ⟶ 102:
==Design==
 
The design of an API has significant impact on its usage.<ref name="Clarke4">{{cite web|url=http://www.drdobbs.com/windows/measuring-api-usability/184405654|title=Measuring API Usability|last1=Clarke|first1=Steven|date=2004|website=Dr. Dobb's|accessdate=29 July 2016}}</ref> 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