Professor Turing

Study guides

What is an API? The request, the response and the contract

Last updated: 2026-11-26

An application programming interface, or API, is a connection that lets one piece of software use a service offered by another. Its documentation or specification says what may be asked and what comes back, which is why, as Wikipedia notes, people liken an API to a contract. In a web API, the call travels as a request and the answer returns as a response with a status code, headers and often a body. The caller works from what the contract promises and does not need to know how the service is built.

Start learning No account needed

1. The boundary, and the contract that defines it

A user interface links a person with a computer. An API links programs or computers with one another, and apart from the programmer who builds it into software, people are not meant to use it directly. Wikipedia also separates two meanings of the word. The written description of the connection is called the API specification, and a system built to match it implements, or exposes, the API. So "the API" can mean the description or the thing that answers.

A web API is the kind you meet in web development. A server-side web API offers one or more endpoints, the places where requests are sent, with defined request and response messages. The data is typically JSON or XML, usually carried by a web server over HTTP. A call may use a method such as GET with a path and query parameters, and the reply has a status line, headers and often a body.

2. A worked example: one request, one response

Suppose a study-room booking service documents this API. A caller sends HTTP GET to /rooms with building and floor as query parameters. The reply is status 200 with a JSON body holding building, floor, open_now and rooms, where each room has the fields name, capacity and projector. Any other path gets status 404 with an empty body. The script stands in for both sides without using a network: it builds the request, answers it, checks the fields, then asks for an undefined path:

Request
  GET /rooms?building=main&floor=2
Response
  status: 200 OK
  content-type: application/json
  body members:
    building: "main"
    floor: 2
    open_now: true
    rooms: an array of 3 objects
      {"name": "Room 201", "capacity": 8, "projector": true}
      {"name": "Room 204", "capacity": 4, "projector": false}
      {"name": "Room 208", "capacity": 12, "projector": true}
Field names and types match the contract: True
Rooms seating 8 or more: Room 201, Room 208

Request
  GET /desks
Response
  status: 404 Not Found
  body: empty, so the caller checks the status before parsing
checks passed

The field checks are the lesson. The caller did not reach into the service's database or depend on its internal code; it sent one documented request, got one response, and checked names and types before using the data. The last exchange is part of this contract too: /desks is not defined, so the answer is 404 Not Found with nothing to parse. A caller that reads the status first can handle that case deliberately.

3. A common misconception: an API is a website or a library

Both a website and a web API can sit at web addresses, and a browser can open either, so the two blur together. The difference is who the response is for. A page in a user interface is built for a person to read and use; an API response is built for a program to act on. One company may offer both.

The library reading mixes up code with its interface. A library is a body of code that does the work, and the interface it offers to your program is itself a kind of API: the interface states how things should behave, and the library carries that out. One API can have several implementations. A web API is another type, where the call goes to a server, so the request and response travel as messages. "API" therefore does not mean only "something on the web", and it does not name the code behind the interface unless a speaker is using the word for the implementation.

4. Test yourself

Three questions before you scroll back. First: one address on a server returns a page meant for reading and another returns JSON meant for a program; which one is the web API, and why? Second: in the worked example, which parts make up the successful request, and which three parts make up the response? Third: what should the caller check before parsing a body? Then check: the JSON address, because a program consumes it; the method GET, the path /rooms and the query parameters building and floor, then the status, the content-type header and the body; the status code. The one you fumbled is the piece to study next.

For interview practice, see how to prepare for a coding interview, and for checking yourself without help, how to test yourself.

What the sources found, and their limits

Wikipedia, "API". It covers the definition, the contrast with a user interface, specification and implementation, library interfaces as a type of API, and the contract comparison. Source: API, read on 2026-11-25.

Wikipedia, "Web API". It covers client-side and server-side web APIs, endpoints, request and response messages, and the usual JSON or XML data over HTTP. Source: Web API, read on 2026-11-25.

Wikipedia, "HTTP". It covers request methods including GET, the response start line with its status code and optional reason phrase, headers, and the classes of status code. Source: HTTP, read on 2026-11-25.

Limits: three encyclopedia articles, not course texts or standards documents. The booking service and its contract are ours, and scripts/what-is-an-api-worked-example.py checks only that its own two exchanges follow that contract. All three articles are CC BY-SA.

How Professor Turing helps

Professor Turing is a tutor for adults learning any subject, in college or on their own. It asks you questions instead of giving the final answer, does not grade a bare guess, and remembers what you got wrong. No account is needed to start.

Bring the call or the error you are untangling, such as a 404 where you expected data. Its first reply asks what you already know before it teaches anything. If you answer with a bare guess, it asks how you got there instead of saying right or wrong, and when you stay stuck it changes its approach and makes the next step smaller instead of handing over the answer. Later in a session it can offer a short test without help, scored apart from the tutoring, so you can tell what you can do alone from what the tutor carried you through. You must be 18 or older, and guest conversations are deleted 7 days after the last activity.

FAQ

Is an API just a website? No, though a web API can use the same web server and the same protocol. A website offers pages for a person to read and use, while an API offers a service to other software. Some APIs are not on the web at all, such as the interface of a software library.

What actually passes between the two programs? In a web API, a request goes one way and a response comes back. In this page's example the request is the method GET, a path and query parameters. The response has a status code, an optional reason phrase, headers such as content-type, and a JSON body. The documented contract says which requests exist and which fields come back.

Start with what you're working on

Tell the tutor which call or response you are working through and let it ask you the questions.

Start learning No account needed

See also: how to prepare for a coding interview · how to test yourself · framework and library · all study guides