48

Question

I have a probably rather simple question, but I'm unable to find an answer with nice explanations:

What is the difference (if any) between a route and an endpoint in the context of a RESTful API developed within a Node.js / Express application (but these concepts may be broader?!)?
(Does it relate to URLs in some way?)

Example

For example, in this article: https://medium.com/@purposenigeria/build-a-restful-api-with-node-js-and-express-js-d7e59c7a3dfb we can read:

We imported express which we installed at the beginning of the course, app.get makes a get request to the server with the route/endpoint provided as the first parameter, the endpoint is meant to return all the todos in the database.

These concepts are used interchangeably, which makes me confused.
(please note that I'm a 100% beginner with REST API, nodejs and express but I try to do my best to learn).


Edit

The two first answers chronologically speaking make me even more confused as they are perfectly antagonistic.

6 Answers 6

73

3 different concepts here:

  • Resource: {id: 42, type: employee, company: 5}
  • Route: localhost:8080/employees/42
  • Endpoint: GET localhost:8080/employees/42

You can have different endpoints for the same route, such as DELETE localhost:8080/employees/42. So endpoints are basically actions.

Also you can access the same resource by different routes such as localhost:8080/companies/5/employees/42. So a route is a way to locate a resource.

2
7

Routes and endpoints are associated concepts - you can't really have one without the other.

What is an endpoint?

Generally speaking, an "endpoint" is one end of a communication channel where one system interacts with another system. This term is also used similarly in networking.

For a typical web API, endpoints are URLs, and they are described in the API's documentation so programmers know how to use/consume them. For example, a particular web API may have this endpoint:

GET https://my-api.com/Library/Books

This would return a list of all books in the library.

What is a route?

A "route" is typically code that matches incoming request paths to resources. In other words, it defines the URL and what code will be executed. A route path might contain regular expressions, patterns, parameters, and involve validation. For example, consider this route path:

"{controller}/{action}/{id?}"

In ASP.NET, pattern matching is applied, so GET https://my-api.com/Library/Books/341 would call the Books public method on the Library class, passing a parameter of 341. Routing frameworks can be very flexible and versatile.

The simplest example of an endpoint is to put a file you want to be consumed (say data.json) inside the public_html folder of your web server. It can be reached by GET https://my-api.com/data.json. The routing is handled by the web server out of the box and no routing code is required.

Some good things to read next:

5

Route

  • URI path used to access the available endpoints.
  • example: http://www.mywebsite.com/

Endpoint

  • performs a specific action.
  • has one or more parameter(s).
  • returns back data.
  • example: GET http://www.mywebsite.com/Products

A Route is the URI, and the Endpoint is the action performed on the URI.

0

Endpoints are basically use to perform specific task and return data and endpoints are kind of part of a route.

For example is route and this is also a route but here both of them are returning different data not he same so, we can say that the last two parameter here is kind of end point means the id and question string.

endpoints:

 /56075017/difference-between-route-and-endpoint
 /56040846/how-to-use-the-classweight-option-of-model-fit-in-tensorflow-js

route:

https://stackoverflow.com/questions/56075017/difference-between-route-and-endpoint
https://stackoverflow.com/questions/56040846/how-to-use-the-classweight-option-of-model-fit-in-tensorflow-js
0

In this example: http://example.com/my-website/comments/123:

Route:

my-website/comments/123

Endpoints: (a fancy word for a URL with an action)

  • GET http://example.com/my-website/comments/123. returns the comment data.
  • DELETE http://example.com/my-website/comments/123. deletes the comment and returns the now-deleted comment data.
0

endpoints : external address where clients can send requests

routes : internal server configuration that defines how requests to a specific URL pattern or HTTP method should be handle

in the other words endpoints are what clients interact with, while routes are how the server organizes and responds with those interaction

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.