Search code examples
apiresthttpxmlhttprequest

What is the main difference between HTTP request to a website VS HTTP request to the REST API?


I have been trying to wrap my head around this and I'd appreciate if someone could enlighten me.

What is the main difference between making a "HTTP GET" request to a webpage and fetching the HTML VS making "HTTP GET" request to a REST API endpoint and fetching JSON?

As far as I know, REST API can also return HTML, so in that case, what would be the main differentiator between these two?

I may be missing something obvious here but I am just trying to conceptualize each action so I have no more ambiguity.

Thanks in advance.


Solution

  • What is the main difference between making a "HTTP GET" request to a webpage and fetching the HTML VS making "HTTP GET" request to a REST API endpoint and fetching JSON?

    Not much?

    In the REST architectural style (which is followed by HTTP... mostly). an important constraint is uniform interface, which includes the idea that all resources understand all messages the same way.

    That means we can do things like use a general purpose web browser to fetch documents, or a general purpose cache to store representations, without needing any special code to distinguish "web resources" from "api resources".

    A "good" REST API looks like a machine readable web site.

    The only difference that you might notice in some cases is that the hypermedia representations of resources might use some standardized format that isn't HTML.

    Otherwise, they are the same thing - the main difference being that a "REST API" tends to have more resources that are expected to be changed by incoming requests, as opposed to a website which is designed more for reading than editing. So PUT/POST/PATCH requests are more commonly used with API resources.