ArticleslgStudy

computer science

Web API

Web API is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Web API rather than just read about it. In short: A web API is an application programming interface (API) for either a web server or a web browser. It can refer to a client-side JavaScript API (including any web frameworks being used) or a server-side web API.

Web API — main illustration
Web API — illustration

Key takeaways

  • Web API belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Web API to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Web API from memory before moving on to harder problems.

Reference excerpt

A web API is an application programming interface (API) for either a web server or a web browser. It can refer to a client-side JavaScript API (including any web frameworks being used) or a server-side web API. The latter consists of one or more endpoints to a defined request–response message system, typically expressed in JSON or XML by means of an HTTP-based web server. A server API (SAPI) is not considered a server-side web API, unless it is publicly accessible by a remote web application.

Client side A client-side web API is a programmatic interface to extend functionality within a web browser or other HTTP client. Originally these were most commonly in the form of native plug-in browser extensions however most newer ones target standardized JavaScript bindings. The Mozilla Foundation created their WebAPI specification which is designed to help replace native mobile applications with HTML5 applications.

Server side A server-side web API consists of one or more publicly exposed endpoints to a defined request–response message system, typically expressed in JSON or XML. The web API is exposed most commonly by means of an HTTP-based web server. Mashups are web applications which combine the use of multiple server-side web APIs.

Endpoints Endpoints are important aspects of interacting with server-side web APIs, as they specify where resources can be accessed by third-party software. Usually the access is via a URI to which HTTP requests are posted, and from which the response is thus expected. Web APIs may be public or private, the latter of which requires an access token.

Resources versus services Web 2.0 Web APIs often use protocols such as REST and SOAP. RESTful web APIs use HTTP methods (verbs) to access resources, and typically use JSON or XML to transmit data. By contrast, SOAP protocols are standardized by the W3C and mandate the use of XML as the payload format, typically over HTTP. Furthermore, SOAP-based Web APIs use XML validation to ensure structural message integrity, by leveraging the XML schemas provisioned with WSDL documents. A WSDL document accurately defines the XML messages and transport bindings of a Web service.

Growth and impact The number of available web APIs has grown consistently over the past years, as businesses realize the growth opportunities associated with running an open platform, that any developer can interact with. ProgrammableWeb tracks over 24000 Web APIs that were available in 2022, up from 105 in 2005. Web APIs have become widely used across modern software applications. There are few major software applications/services that do not offer some form of web API. A common form of interacting with these web APIs is via embedding external resources, such as tweets, Facebook comments, YouTube videos, etc. There are companies, such as Disqus, whose main service is to provide embeddable tools, such as a comment system. Every website in the TOP 100 Alexa Internet ranked websites uses APIs and/or provides its own APIs. As the number of available web APIs has grown, open source tools have been developed to provide more sophisticated search and discovery. APIs.json provides a machine-readable description of an API and its operations, and the related project APIs.io offers a searchable public listing of APIs based on the APIs.json metadata format.

Business

Commercial Many companies and organizations rely heavily on their Web API infrastructure to serve their core business clients. In 2014 Netflix received around 5 billion API requests, most of them within their private API.

Governmental Some governments are now opening up access to some of the data they collect. The interfaces through which this data is typically made accessible are web APIs. Web APIs allow for data, such as "budget, public works, crime, legal, and other agency data".

Example An example of a popular web API is the Astronomy Picture of the Day API operated by the American space agency NASA. It is a server-side API used to retrieve photographs of space or other images of interest to astronomers, and metadata about the images. According to the API documentation, the API has one endpoint:

https://api.nasa.gov/planetary/apod

The documentation states that this endpoint accepts GET requests. It requires one piece of information from the user, an API key, and accepts several other optional pieces of information. Such pieces of information are known as parameters. The parameters for this API are written in a format known as a query string, which is separated by a question mark character (?) from the endpoint. An ampersand (&) separates the parameters in the query string from each other. Together, the endpoint and the query string form a URL that determines how the API will respond. This URL is also known as a query or an API call. In the below example, two parameters are transmitted (or passed) to the API via the query string. The first is the required API key and the second is an optional parameter — the date of the photograph requested.

https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY&date=1996-12-03

Visiting the above URL in a web browser will initiate a GET request, calling the API and showing the user a result, known as a return value or as a return. This API returns JSON, a type of data format intended to be understood by computers, but which is somewhat easy for a human to read as well. In this case, the JSON contains information about a photograph of a white dwarf star:

The above API return has been reformatted so that names of JSON data items, known as keys, appear at the start of each line. The last of these keys, named url, indicates a URL which points to a photograph:

https://apod.nasa.gov/apod/image/9612/ngc2440_hst2.jpg

Following the above URL, a web browser user would see this photo:

Although this API can be called by an end user with a web browser (as in this example) it is intended to be called automatically by software or by computer programmers while writing software. JSON is intended to be parsed by a computer program, which would extract the URL of the photograph and the other metadata. The resulting photo could be embedded in a website, automatically sent via text message, or used for any other purpose envisioned by a software developer.

See also Dynamic web page Overview of RESTful API Description Languages REST GraphQL Web service

References

… excerpt ends here. Continue reading the full article.

Illustrations

Web API: An API in the context of a computer network
An API in the context of a computer network
Web API: Screenshot of web API documentation written by NASA
Screenshot of web API documentation written by NASA
Web API illustration

Worked examples

Example 1 — a first encounter with Web API

Start with the simplest possible case. Write down what Web API claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Web API before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Web API ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Web API

In research
Web API appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Web API in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Web API is common in secondary-school and first-year university syllabi. It links to neighbouring topics Application programming interfaces, Software architecture, Web 2.0 neologisms, so understanding it makes those chapters shorter.
In everyday life
Look for Web API outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Web API” →

How to study Web API in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Web API means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Web API out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Web API in simple terms?

A web API is an application programming interface (API) for either a web server or a web browser. It can refer to a client-side JavaScript API (including any web frameworks being used) or a server-side web API.

Why does Web API matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Web API?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Web API.

Tags

  • Application programming interfaces
  • Software architecture
  • Web 2.0 neologisms
  • Web development

Keep exploring