4

The following link refers to the MDN page where a host of Web APIs and interfaces are listed:

https://developer.mozilla.org/en-US/docs/Web/API

However, there is no explanation of what are the main differences between Web API and interface. I also did not succeed in googling any information about interfaces in this sense.

As an inexperienced developer, I would like to know about the theoretical characteristics (bullet points) that distinguish web APIs and interfaces.

Can someone explain to me this or refer where can I read more about it?

For example, In the link that I am refering to CSSOM model is cosidered as a set of APIs and listed under a category of WEB APIs, meanwhile CSSStyleDeclaration is considered an INTERFACE and listed under the category of Interfaces. I am particularly interested in what are the differences between those two categories (Web APIs and Interfaces)?

E_net4
  • 27,810
  • 13
  • 101
  • 139
Linas M.
  • 312
  • 1
  • 3
  • 17
  • API running in the web is web api in simple terms. Build a simple api and you will start understanding it. Mainly we use web api in communicating with distributed systems. – yogihosting Oct 25 '20 at 13:46
  • @yogihosting — That isn't what the page referenced means by API. – Quentin Oct 25 '20 at 13:48
  • @yogihosting the question is about what is the difference between web api and interface, not about what is web api. – Linas M. Oct 25 '20 at 13:51
  • @LinasM. The "I" in API = Interface. – Dshiz Oct 25 '20 at 13:52
  • @Dshiz I know that the "I" means Interface, but if you look at the page I am referencing to, you would see that web apis and interfaces are listed under differenct categories, I'm interested why and what are the differences? – Linas M. Oct 25 '20 at 13:58
  • 1
    Actually, I think it is dividing Web APIs into Specifications and Interfaces, and it defines interfaces as object types in the first paragraph. – thebjorn Oct 25 '20 at 14:00

2 Answers2

3

Many people, me included, use them quite interchangeably (as in "the API to the screen object" or "the interface to the requests library"), however MDN is more precise and defines API as a specification involving multiple interfaces, and an interface as an object type (i.e. which methods are available on an object).

As an example, take the URL API, one of the simplest APIs:

The URL API is a component of the URL standard, which defines what constitutes a valid Uniform Resource Locator and the API that accesses and manipulates URLs. The URL standard also defines concepts such as domains, hosts, and IP addresses, and also attempts to describe in a standard way the legacy application/x-www-form-urlencoded MIME type used to submit web forms' contents as a set of key/value pairs. -- https://developer.mozilla.org/en-US/docs/Web/API/URL_API

The URL API only defines two interfaces URL, and URLSearchParams:

The URL API is a simple one, with only a couple of interfaces to its name ... -- (bottom of the link above).

The URL interface (https://developer.mozilla.org/en-US/docs/Web/API/URL) defines which parameters the constructor takes, which properties are available, and which methods and static methods are available on the object you get back from the URL constructor.

thebjorn
  • 26,297
  • 11
  • 96
  • 138
2

tl;dr: Just think of specification as a set of one or more related interfaces.

For example, the Document Object Model (DOM) specification cannot be used directly in your JavaScript code. The DOM, however, has many interfaces that you can instantiate and use methods (Document, Element, DOMString, etc).

Rodrigo Amaral
  • 1,324
  • 1
  • 13
  • 17