Essential CSS
JavaScript Roadmap
Learn JavaScript
Mastering Web Typography
Practical Astro
Understanding Async JS
Unorthodox Tailwind
API Masterclass
Build and Deploy
The Beginner Freelancer
Real World Node
Profile Billing Logout
Understanding Async JS
Lesson Plan
  1. Introduction
    1. What is Asynchronous JS?
    2. Callbacks are not automatically asynchronous
    3. What is an API?
    4. Evolution of HTTP APIs
    5. Ajax vs Asynchronous JavaScript
  2. Fundamental Concepts
    1. How to fetch resources
    2. Using XHR
    3. Using the Fetch API
    4. Using libraries
    5. Core JavaScript concepts
    6. Understanding Promises
    7. Understanding Async Functions
    8. Understanding the Event Loop
    9. Understanding JSON
    10. Async JS Best Practices
    11. Using Optimistic UI
  3. Understanding Rest API
    1. Diving into Rest APIs
    2. The Rest Architecture
    3. The Rest Structure
    4. Anatomy of a Request
    5. What's an endpoint
    6. Request methods
    7. Understanding request headers
    8. Understanding the request body
    9. Authentication
    10. Basic Authentication
    11. Bearer Authentication
    12. Authenticating with API keys and API Secrets
    13. Cross Origin Resource Sharing
    14. Anatomy of a response
    15. HTTP Statuses
    16. Response headers
    17. The response body
    18. Handling Errors
    19. Reading API documentations
    20. Understanding Curl
  4. Node Basics
    1. Why we are using Node
    2. Command Line Basics
    3. Installing Node
    4. Managing dependencies
    5. Using ES Modules in Node
    6. Using Node
    7. Restarting the server automatically
    8. Sending requests via Node
    9. Protecting API keys and secrets
  5. Building a server
    1. What's a server
    2. Building a simple server with Express
    3. Two kinds of servers
    4. API Server architecture
    5. Handling routes
    6. Understanding Middlewares
    7. Enabling CORS
    8. Receiving data
    9. Sending responses
    10. Handling errors in Express
    11. Using the server as a proxy
    12. Minimum viable server
  6. Open Authorization
    1. Open Authorisation (OAuth)
    2. Authenticating with Access Tokens
    3. Obtaining Access Tokens
    4. Public and Confidential Clients
    5. Authorisation Code Grant
    6. Understanding scope
    7. Proof Key for Code Exchange (PKCE)
    8. PKCE with Twitter
    9. Dynamic state and `code_verifier`
    10. Saving the access token in cookies
    11. Passing access tokens to the browser
    12. Saving the access token in local storage
    13. Refresh Token Grant
    14. Device Code Grant
    15. Client libraries vs REST
  7. Building Social Media Logins
    1. Introduction
    2. Starter Files
    3. Creating SSL certificates
    4. Login in with Github
    5. Github: Saving the token to local storage
    6. Github: Persisting the login status
    7. Login with Twitter
    8. Twitter: Saving the token to local storage
    9. Twitter: Persisting the login status
    10. Twitter: Refreshing the access token
    11. Login with Facebook
    12. Facebook: Saving the token to localStorage
    13. Facebook: Persisting the login status
    14. Facebook: Refreshing the access token
    15. Login with google
    16. Google: Saving the token to localStorage
    17. Google: Refreshing the access token

Evolution of HTTP APIs

4m:45s

Both Rest API and GraphQL is can be contained by a broader group known as HTTP APIs.

HTTP stands for HyperText Transfer Protocol. It determines how computers communicate with other computers over a network.

If you noticed the http or https part of a URL, you would have observed HTTP APIs in use.

Now, HTTP APIs have evolved over the years and many standards have been created.

For this course, you have to know that APIs have four major evolutionary points:

  1. 1991 — CORBA (Common Object Request Broker Architecture)
  2. 1999 — SOAP (Simple Object Access Protocol)
  3. 2003 — REST (Representational State Transfer)
  4. 2015 — GraphQL (Graph Query Language)

Today, REST and GraphQL are the two most popular structures. Nobody uses CORBA anymore, but enterprises may still use SOAP.

Common Object Request Broker Architecture — COBRA

CORBA was the first API.

It created a pattern where a client (a computer) needs to be able to communicate with a server (another computer).

This API says:

  • The client must send a request to the server
  • Then the client must wait for a response from the server
  • Then the client can do what it wants with the response

Sounds familiar? Well, CORBA paved the way for how we fetch resources today.

There were two problems with CORBA:

  1. Nobody created a specification on how to send requests and receive responses so each CORBA request and response needs to be custom created between the user and the vendor. (This takes a lot of work).
  2. The CORBA spec had gaps which was covered by vendor companies. Iona (a company) had a monopoly share (around 80%) in the industry.

Lots of people decided to stop using Iona and that eventually led to the creation and adoption of SOAP.

Simple Object Access Protocol — SOAP

SOAP did not require bespoke systems to be created between each company. It used a common interface called XML (Extensible Markup Language).

XML looks very much like modern HTML except you can use anything for the tags. There are no standardised tags you need to follow.

<!-- XML Example -->
<Customer>
<Order orderID="123"> … </Order>
<Order orderID="456"> … </Order>
</Customer>

The most important thing about SOAP is you can send a request to one endpoint to grab anything you want.

A SOAP request can look like this (I grabbed the image from this article)

Example of a SOAP Request

SOAP had a reputation for being hard to use and debug (mostly because it used XML). Apparently, parsing XML and getting error messages in XML is rather difficult.

And the next evolution is REST (which currently still the de-facto standard today).

Representational State Transfer — REST

There are several major noteworthy points about the REST architecture.

Here are the important ones to know for now. (I’ll talk about the rest as we go through the REST API chapter).

  1. There’s a creation of HTTP verbs like GET, POST, PUT, PATCH and DELETE, which allows more standardisation of the types of requests.
  2. REST allows a server to send information on how one should consume the data, so it made it easy for browsers to handle different data types like text, XML, images, PDF documents, JSON, etc.

In 2000, Roy Fielding filed a dissertation about REST. Around the same time, in 2001, Douglas Crockford discovered JSON and went on to popularise it.

The rise of REST is most probably brought about by a combination of the following events:

But REST came with one problem: You may need to fetch many different resources to get every piece of information you need.

In contrast, you only had to send one request if you use SOAP.

This frustration eventually resulted in the creation of GraphQL.

Graph Query Language — GraphQL

GraphQL sits above a REST API, and it lets you define the structure of the data you wish to obtain.

The backend, after receiving the structure, will gather only the information you need, and send it back to you.

In this regard, GraphQL is very similar to SOAP.

The major difference is GraphQL defaults to JSON (but you can use XML) while SOAP requires you to use XML.

REST vs GraphQL

In the tech world, many people make the mistake of saying “X-techology is dead, Y-technology is the future”. People also say GraphQL is the future and you should use GraphQL over REST.

But if you’ve been following this very short history, you’ll know when to use REST and when to use GraphQL.

In simple terms:

  • Use REST when your application is pretty simple and you can get everything from REST endpoints easily
  • Use GraphQL if your application requires too many REST requests (you kinda need to run into REST problems to know what this means 😜).

But there’s a caveat: you can only use GraphQL if the API server supports GraphQL.

To date, most APIs support Rest and not GraphQL, so you may have a tough time finding GraphQL APIs.

Further Reading

If you’re the nerdy kind wants to read further, I found these resources extremely helpful in figuring out what I’ve just told you.