Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Write a Basic Fetch Request

What's the difference between the fetch API and calling a website an "API" (ex. the Random User Generator API)?

.

1 Answer

Eric M
Eric M
11,545 Points

Hi Amandeep,

At its most broad, an Application Programming Interface is a way of interacting with code that you didn't write.

A REST API is a type of web API used for communication over a network, like the internet. You send a structured request to the server, and it returns a structured response and perhaps performs some sort of action with the code running on the server (like creating, changing, or recording some data).

Let's say I'm writing a new graphics package in Rust but I want people who don't know Rust to be able to use it to draw graphics on the screen. I might write a JavaScript API and a Python API for interacting with my graphics package so that other programmers who know those languages can use this software to draw graphics. In this case my package handles all of the interaction with the drivers and operating system, but after you import the JavaScript API to your JavaScript project you can just write ericsGraphics.drawSquare(coordinates) and not have to worry about the underlying code. We call this (and many other things) an abstraction, the act of communicating with the graphics hardware and operating system have been abstracted away, or simplified, by the API.

The Fetch API (and the XMLHttpRequest API) perform this sort of abstraction for web communications, and are themselves used to communicate with web APIs.