Coding

What Is an API Endpoint? URLs, Methods and Examples

An API endpoint is a specific URL where an API accepts requests and does one job, such as GET https://jsonplaceholder.typicode.com/posts/1 to fetch post number 1. The API is the whole collection of endpoints plus the rules for using them.

If you are new to the term, think of an API as a building and each endpoint as a numbered door. You pick the door by its address, and the kind of request you send decides what happens inside.

What an API endpoint looks like

JSONPlaceholder is a free practice API that returns fake data, and its guide lists its routes. These are real endpoints from that guide:

RequestWhat it does
GET /postsReturns the list of posts
GET /posts/1Returns post number 1
GET /posts/1/commentsReturns the comments that belong to post 1
POST /postsCreates a post
PUT /posts/1Replaces post 1
PATCH /posts/1Changes some fields of post 1
DELETE /posts/1Deletes post 1

Notice that four of these requests share the path /posts/1 and differ only in the method. That is why people sometimes say an endpoint is "a URL plus a method". The two ideas are close enough that you rarely need to separate them, but the difference explains why documentation lists both.

The parts of an endpoint URL

An endpoint is a normal URL, so it follows the generic syntax in RFC 3986: a scheme, an authority (the host name), a path, and an optional query. Here is one split into its parts:

https://jsonplaceholder.typicode.com/posts?userId=1
\___/   \_________________________/\____/ \_______/
scheme   host (authority)            path   query
  • Base URL: the scheme and host, plus any shared prefix such as /v1 if the API has one. Every endpoint of the API starts with it. The OpenAPI specification describes the same split: the path "is appended to the URL from the Server Object in order to construct the full URL".
  • Path: picks the resource. In /posts/1/comments, posts is a collection, 1 is one item in it, and comments is a collection nested under that item (the guide's "nested routes").
  • Query string: starts at the first ? and filters or shapes the result. JSONPlaceholder's guide shows /posts?userId=1 returning only the posts of the first user, and notes that /posts/1/comments is equivalent to /comments?postId=1.

The query is not part of the path in OpenAPI either. The specification describes query parameters as parameters "appended to the URL with the ? character", so /posts?userId=1 is the endpoint /posts called with a parameter.

Path parameters: one endpoint, many URLs

The 1 in /posts/1 is a variable. The same endpoint answers /posts/2, /posts/3 and so on. API documentation writes this with a placeholder, and OpenAPI uses curly braces for it:

GET /posts/{id}

OpenAPI calls this path templating: "template expressions, delimited by curly braces ({}), to mark a section of a URL path as replaceable using path parameters". When you read documentation, treat /posts/{id} as a single endpoint, even though it covers every post.

Call an endpoint yourself

You can call a public endpoint from a terminal. On macOS and Linux, and in Windows 11's Command Prompt, curl works. In Windows PowerShell 5.1, type curl.exe, because plain curl there is an alias for Invoke-WebRequest.

curl https://jsonplaceholder.typicode.com/posts/1

Example output (the exact text may differ):

{
  "userId": 1,
  "id": 1,
  "title": "...",
  "body": "..."
}

The response is JSON: the fields of post 1. Change the number and you get a different post, from the same endpoint. To send data to a POST endpoint from code instead, see Python requests POST JSON.

In a browser, you can paste the same URL into the address bar, because a browser address bar sends GET. That works for read-only endpoints. Endpoints that create or delete things need a method the address bar cannot send, so you use curl, a REST client or code.

Endpoint, resource, route: what the words mean

These words overlap, and documentation does not use them consistently.

  • Resource: the thing the API manages, such as a post or a user. /posts/1 addresses one resource.
  • Endpoint: where you reach it. OpenAPI itself calls the entries under its Paths Object "the relative paths to the individual endpoints and their operations", so it treats the path as the endpoint and the methods as operations on it.
  • Route: the server developer's word for the same thing, because the server routes each incoming URL and method to a piece of code. JSONPlaceholder's guide has a "Routes" section listing the endpoints above.

If a definition seems to differ between two tutorials, one counts paths and the other counts path and method pairs. Both are fine, and the documentation you are using decides which you need.

What happens when you hit the wrong endpoint

Most mistakes come from the address rather than the data. The usual symptoms:

  • 404 Not Found: the path or ID does not exist. Check for typos, a missing version prefix such as /v1, and the base URL.
  • 401 or 403: the endpoint exists, but your credentials are missing or not allowed to use it.

HTTP status codes explained covers these and the rest of the common codes. If a browser app fails while curl to the same endpoint works, the cause is usually the browser's cross-origin check, explained in CORS error explained.

Finding the endpoints of an API

Start with the provider's API reference. It normally gives a base URL, then lists each endpoint with its method, parameters and an example response. Many providers also publish an OpenAPI document, a machine-readable file that lists every path and the operations available on each. The specification says a Path Item "describes the operations available on a single path", with one field per HTTP method, so a tool reading the file can show you all the endpoints at once.

When you copy an example, check three things before you run it: the base URL, the method, and whether the path contains a placeholder such as {id} that you must replace.

Frequently asked questions

Is an API endpoint the same as a URL?
An endpoint is a URL with a job attached. The URL is the address, and the endpoint is that address together with what the API does there, which depends on the HTTP method. The same URL, such as /posts/1, can read, replace or delete a post depending on whether you send GET, PUT or DELETE.
How many endpoints does an API have?
As many as its designer defines. A small API may have a handful, a large one hundreds. Counting conventions differ: some people count each path once, and others count each path and method pair separately, so GET /posts and POST /posts are two endpoints.
What is the difference between an endpoint and a base URL?
The base URL is the shared prefix for the whole API, for example https://jsonplaceholder.typicode.com. An endpoint adds a path to it, such as /posts/1. OpenAPI describes this the same way: the path is appended to the server URL to build the full URL.
Where do I find an API's endpoints?
In the provider's API reference. Many providers also publish an OpenAPI file that lists every path and the methods it supports. If the documentation lists a base URL and a set of paths with methods, those are the endpoints.

Sources