Front end and back end need a contract to talk — what format do requests and responses follow when a browser calls a server?
Per Wikipedia: “An HTTP API is an interface that exposes application functionality over HTTP using verbs, paths, headers and status codes.”
Think of an API as a menu in a restaurant. The front end orders by calling a URL, the back end cooks and returns JSON. HTTP just defines how the waiter carries the order.
- Client forms HTTP request with method and URL
- Server routes request to handler
- Handler runs business logic and queries data
- Server formats JSON response with status code
- Client parses response and updates UI
- Stateless — each request carries its own auth and context
- Uses standard verbs GET POST PUT DELETE
- Versioned via URL or header
- Errors signaled via status codes
# Minimal HTTP API call
import requests
resp = requests.get('https://api.example.com/users/1')
print(resp.status_code, resp.json())- Built from: Client-Server Model — API is the contract inside that model
- Built from: API — specialization of generic API for HTTP
- Related: Server — server implements the API
- Contrasts with: Front End — front end consumes the API
- Forgetting pagination on list endpoints paginates in client not server
- Mixing HTTP verbs — GET should not change state