Search code examples
routesweb-deploymentrest

What is the difference between an API and routes/endpoints?


I am new to the web world and I just read the difference between a route and an endpoint.

I know the definition of an API. But what is the difference between an API and routes (endpoints)?

It seems to me, when somebody says "build an API" or according to the YouTube tutorials that I have watched, they simply build a route using web frameworks like Express.js or Flask like '/hello', which returns "hello".

If that is an API, are an API and a route interchangeable? Like, if I have, for example, 3 routes: '/hello', '/users', '/users/<userId>'. Can I say I have 3 APIs?


Solution

  • In short to my mind:

    • API is about working with data using JSON or XML (as a rule) for input/output data (CRUD operations without any UI). API should follow some rules and structure. Ex.: GET /{entity_type}/{entity_id} means that this method will try to get entity with passed type and id
    • endpoint may be an API (they often are spelled together like "API endpoint") but at the same time it may be just an URL that leads somewhere without explicit manipulation with any data, for instance, trigger/webhook/gateway etc.
    • route is a path to some website/page/controller with a meaningful name to interact with the user. Route receives some user input (handles user actions) and represents some results in a convenient way (for example, render markup).