Endpoint
In short
An endpoint is a specific URL, combined with an HTTP method, where an API receives requests and returns responses for one particular resource or action.
What is an API endpoint?
An endpoint is one specific address where an API can be reached. In a web API, it is a URL such as https://api.example.com/users, usually paired with an HTTP method, so GET /users and POST /users are often treated as two different endpoints that do different things.
An endpoint URL typically has a base URL with the API's domain and version, like https://api.example.com/v1, a path that names the resource, like /users/42, and optional query parameters that filter or sort the results, like ?sort=name. The API's documentation lists each endpoint, the data it expects, and the response it returns.
If an API is a restaurant menu, each endpoint is a single item on it: one specific thing you can order, with a clear description of what you get. A typical REST API has dozens of endpoints, while a GraphQL API usually exposes just one and lets the query decide what data comes back.
People sometimes use endpoint, route, and API interchangeably. The API is the whole interface, an endpoint is one entry point into it as seen by clients, and a route is the server-side rule that connects a URL and method to the function that handles it. In networking and security, endpoint can also mean a device such as a laptop or phone, which is a different meaning.
Key takeaways
- An endpoint is a URL where an API accepts requests.
- The same URL with different HTTP methods can act as different endpoints.
- Endpoint URLs combine a base URL, a resource path, and optional query parameters.
- REST APIs have many endpoints; GraphQL APIs usually have one.
Example
// Each route below defines one endpoint of a users API (Express.js)
app.get("/v1/users", listUsers); // GET /v1/users
app.get("/v1/users/:id", getUser); // GET /v1/users/42
app.post("/v1/users", createUser); // POST /v1/users
app.patch("/v1/users/:id", updateUser); // PATCH /v1/users/42
app.delete("/v1/users/:id", deleteUser); // DELETE /v1/users/42
// A client calling one of those endpoints
const res = await fetch("https://api.example.com/v1/users/42");Readers ask
What is the difference between an API and an endpoint?
An API is the complete interface a service offers, while an endpoint is one specific URL and method within that API. For example, a weather API might have separate endpoints for current conditions and for forecasts.
What is the difference between an endpoint and a route?
They describe the same thing from different sides. Clients call an endpoint, while a route is the server-side rule that maps that URL and HTTP method to the code that handles it.
See also
- APIBackend & APIs, p. 2An API is a set of rules that lets one piece of software request data or actions from another in a predictable, documented way.
- REST APIBackend & APIs, p. 38A REST API is a web API that exposes data as resources identified by URLs and lets clients read or change them using standard HTTP methods.
- GraphQLBackend & APIs, p. 19GraphQL is a query language and runtime for APIs that lets clients request exactly the data they need, often from a single endpoint in a single request.
- HTTPWeb Development, p. 19HTTP is the protocol that browsers, apps, and servers use to exchange web pages and data through a simple cycle of requests and responses.
- WebhookBackend & APIs, p. 47A webhook is an automated HTTP request that one application sends to a URL you provide as soon as a specific event happens, such as a completed payment.
Spotted a mistake or something missing on this page?Suggest an edit