Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between route and endpoint?

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.

like image 776
s.k Avatar asked May 10 '19 09:05

s.k


People also ask

What is difference between route and API?

API is usually a definition term, Endpoint or route are physical representation. When somebody says "build an API" that means you have to define its specification e.g. protocol, request/response schema, (may be) security credentials and (of course) an endpoint to hit.

What is a route in an API?

Routes direct incoming API requests to backend resources. Routes consist of two parts: an HTTP method and a resource path—for example, GET /pets . You can define specific HTTP methods for your route. Or, you can use the ANY method to match all methods that you haven't defined for a resource.

What is difference between endpoint and API?

It's important to note that endpoints and APIs are different. An endpoint is a component of an API, while an API is a set of rules that allow two applications to share resources. Endpoints are the locations of the resources, and the API uses endpoint URLs to retrieve the requested resources.

What is the difference between route and path?

A route can be part of a path when only a section of the path is actually traveled. A path is always physical available and may end in a rather unclear manner (e.g A footpath in a forest that blurs away). One or more paths can be part of a route.


3 Answers

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.

  • Read more: Endpoint vs. route

  • Read more: Endpoint vs. resource

like image 125
Jon Portella Avatar answered Oct 12 '22 17:10

Jon Portella


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.

like image 5
Mimina Avatar answered Oct 12 '22 15:10

Mimina


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:

  • Express.js - Routing
  • Wordpress Developer Resources - Routes and Endpoints
  • When to use "client-side routing" or "server-side routing"?
like image 3
CrazyTim Avatar answered Oct 12 '22 16:10

CrazyTim