Adding an API to an AdonisJS Web App

In this series, we'll add a API, using Opaque Access Tokens for authentication, to a preexisting web application. We'll implement dual-guard authentication, add a token management panel, and authenticate our API directly with an organization model!

Difficulty Beginner
What's Inside 43 Lessons
Viewing Time 5h 31m
Sign up to save progress
1

Module 1
Introduction

1.0

Goal of this Series

We'll cover the scope of this series and show some of the functionalities we'll be building throughout, which include an access token management panel, opaque access token authentication using an organization model, and building an API.

2m 52s
1.1

Getting the Web Project Up & Running

We'll get our web project cloned down. Then, we'll get it configured by first creating our database and running our migrations and seeder. Lastly, we'll get a test SMTP email inbox set up through MailTrap.

10m 32s
1.2

Getting Familiar with our Web Project

In this lesson, we'll quickly walk through the web application we've cloned down to get familiar with the data at play, how it's presented to the user, and the features at hand.

4m 10s
1.3

Overview of our Database Schema

In this lesson, we'll take a high level look at our database's schema so that we have an understanding at the entities and models at play and how they relate to one another within our application.

2m 22s
2

Module 2
API Authentication

2.0

Configuring Access Token Auth on top of Session Auth

In this lesson, we'll get opaque access tokens configured within our AdonisJS application on top of the already configured session/web authentication. This will include configuring the guard and setting up the db access token provider.

10m 50s
2.1

Separation of API & Web Auth Guard Concerns

In this lesson, we'll restrict our routes to their applicable authentication guard. Ensuring our web routes can properly authorize using their role-based authorization and our API can properly authorize using our access token abilities.

9m 17s
2.2

Defining Access Token Abilities & DTO

In this lesson, we'll finish up our preparation work by creating a data transfer object (DTO) for our access tokens. Then, we'll define what our token abilities will be within our application's API.

9m 54s
2.3

Creating Access Tokens Part 1: AdonisJS

In this lesson, we'll add a route to the settings portion of our application allowing the user to create an opaque access token (OAT), with the desired permissions, for the active organization.

10m 19s
2.4

Creating Access Tokens Part 2: Inertia/Vue

In this lesson, we'll rig up the create access token route we created in the last lesson to a form within our Vue application. We'll also stub the overall manage access tokens card for the organization itself.

12m 44s
2.5

Opaque Access Tokens (OAT) vs JSON Web Tokens (JWT)

In this lesson, we'll take a step back to understand the differences between the tokens we're using, which are Opaque Access Tokens (OAT), and JSON Web Tokens (JWT). We'll discuss security, scalability, and what makes up each token.

3m 57s

Listing an Organization's Access Tokens

In this lesson, we'll query all of our organization's access tokens and filter out any tokens that are expired. Then, we'll list the organization's tokens showing it's name, abilities, when it was created, and when it was last used.

8m 3s

Displaying & Copying A Newly Created Access Token

In this lesson, we'll add a secondary step to our access token creation flow that will display the newly created access token to the user one time, allow them to copy the token, then drop the token completely from memory.

9m 41s

Deleting/Revoking Access Tokens

In this lesson, we'll add the ability for our users to revoke an access token by deleting it out of our database.

8m 19s
3

Module 3
Getting Started with APIs

The Goal of our REST API

In this lesson, we'll briefly give an overview of REST and how we'll be taking a practical approach to it when building our API.

2m 59s

Our First API Endpoint to Get Our Organization's Details

In this lesson, we'll add the first endpoint to our API. With this endpoint we'll return back the Organization's details for the provided Access Token with the request.

6m 10s

Setting Up Our REST Client

In this lesson, we'll take some time to get set up and get comfortable with a REST Client application. This will allow us to store our API endpoints within collections to simplify testing them as we build them out. In this series, I'll be using Hoppscotch

7m 38s

Simple API Versioning

In this lesson, we'll implement a simple versioning mechanism for our API. Versioning allows us to safely make breaking changes without breaking our user's implementations of our API.

6m 42s
4

Module 4
Organization Resources

Listing Organization Difficulties

In this lesson, we'll begin work on our first CRUD-based API resource by adding the ability to query a list of all our organization's difficulties.

6m 21s

Creating Organization Difficulties

Next, we'll add a POST route and handler so that we can create difficulties from our API

11m 41s

Getting A Specific Difficulty

In this lesson, we'll add a GET API route enabling us to get the details of a specific difficulty by providing the difficulties id via route parameter.

2m 16s

Updating A Difficulty

In this lesson, we'll add a PUT API route to handle updating our difficulties! This route will also accept in a specific difficulty id via route parameter to specify which difficulty should be updated.

2m 55s

Deleting A Difficulty

The last CRUD method we need to add is the ability to delete our a difficulty by adding a DELETE API route, we'll take care of that in this lesson.

4m 26s

Access Level API CRUD

In this lesson, we'll walk through adding API endpoints for the full CRUD (create, read, update, and delete) flow for our organization's access levels.

8m 16s

Status API CRUD

In this lesson, we'll duplicate everything we did one more time for our organization's statuses.

5m 23s

API Authorization Checks

In this lesson, we'll implement our API Authorization checks across all the API controller methods we've implemented thus far. We'll then create a specific access token for each operation (read, create, update, and delete) to ensure everything is working.

9m 26s
5

Module 5
Courses

Listing Courses

Our goal in this step is to add an endpoint that lists our courses. We'll then build upon this endpoint further with the ultimate goal of getting a list of paginated courses.

4m 44s

Creating, Updating, and Deleting Courses

In this lesson, we'll add endpoints to allow creating, updating, and deleting courses from our API. We'll then use this to stub a number of test courses to give us wiggle room to play with our pagination.

7m 4s

Paginating our Course List

In this lesson, we'll transform our courses list endpoint into a pagination endpoint. We'll check and validate our query string for a page and per page parameter that we'll then use to fetch pages of our courses.

7m 30s

Getting A Course's Details, Modules, & Lessons

In this lesson, we wrap up the Courses controller by adding a show method that fetches all the key info for a single course. That includes its modules and lessons, all nicely organized and ready to use in your API response.

3m 54s

Updating A Course's Difficulty, Status, or Access Level

In this lesson, we'll add a specific endpoint with the ability to patch a course's difficulty, status, or access level with a new value so our users have a way to update these without needing to send the entire course payload.

5m 41s

Course Module Nested Resource

In this lesson, we'll work on nested resourceful endpoints for our course modules. We'll add endpoints to create, update, patch, and deleting modules from a specific course.

13m 25s

Getting Just Course Modules & Lessons

In this lesson, we'll remove our GET module route, using the except method on our resource. Then we'll refactor to add a GetModules action

7m 4s

Fixing Our ESLint Integration

I Ran into a ReferenceError and realized our ESLint wasn't working. In this lesson, we'll take a brief aside to fix the linting within our project so it works with ESLint v9

5m 13s

Lesson Operations

In this lesson, we'll implement most of the CRUD functionality for our lessons, including creating, updating, deleting, and patching our lesson's tags. We'll also discuss why we'll treat lessons as a top-level resource.

10m 45s

Getting A Module's Lessons

In this lesson, we'll remove our lesson's index method in favor of a module method whose purpose will be to fetch a module's specific lessons in their stored order.

5m 40s
6

Module 6
Searching

Basic Course Search & Filter

In this lesson, we'll add a new search endpoint for our courses and enable some basic filter functionality along with it. We'll be able to search by course name likeness, status, difficulty, and/or access level.

11m 3s

Advanced String Filtering

In this lesson, we upgrade our course name filter to support both simple strings and advanced object-based queries using VineJS’ union rule. This allows users to specify not just what to search for, but how to search for it.

18m 28s

Filtering by a Number or Array of Numbers

In this lesson, we'll implement our number filtering system in which we'll allow our search APIs to accept a single number or an array of numbers to filter the data by. To validate this, we'll use the union rule from VineJS.

8m 28s

Making our Search Course Action Easily Reusable

In this lesson, we'll make our search course filters optional to increase the reusability of our action. We'll then switch our courses index route handler to use this action.

3m 16s

Searching and Filtering Lessons

In this lesson, we'll take the filters we've created thus far and apply them to a new lessons search endpoint. We'll be able to search our lessons by name, status, access level, and module.

12m 13s

Filtering Lessons by Publication Date

In this lesson, we'll add the ability to search lessons by their publish date and time. We'll utilize before and after properties to allow for filtering that can look forward, backward, or within a specific date range on our lesson's publish at column.

9m 40s

User-Defined Relationship Loading

In this lesson, we'll let our users tell us which relationships they'd like to get back in our lesson search. We'll also discuss how to handle nested relationships and what to watch out for.

6m 35s
7

Module 7
Rate Limiting

Rate Limiting an Organization's HTTP Requests

In this lesson, we'll cover how to throttle how often an organization can hit our API using HTTP Rate Limits, which is crucial for preventing spam, limiting content access, and managing server load.

13m 59s