1 of 27

L21. Designing Your Own REST API

CSCI 344: Advanced Web Technologies

Spring 2026

2 of 27

Announcements

  1. Tutorial 11 Friday (4/17): You will be designing your REST API based on the app you plan to make. Please attend!
  2. Homework 4 (React) is due Monday (4/20)
  3. Your Project Proposal and wireframe is due next Wednesday (4/22)

3 of 27

Outline

  1. Services, hosts, and ports
  2. Databases
  3. Building a REST API

4 of 27

Outline

  • Services, hosts, and ports
  • Databases
  • Building a REST API

5 of 27

What is a service?

  • What are some examples of services we’ve already been using in this class?
  • A service is a program that runs in the background and listens for / responds to certain kinds of messages.
  • Performs automated tasks, responds to hardware events, or listens for data requests from other software.
  • Often loaded automatically at startup, and run in the background, without user interaction

On a Mac: lsof -i -P | grep -i "listen"

On a Windows: Control Panel > Administrator Tools > Service Icon

6 of 27

What is a port?

  • Ports are managed by the operating system
  • Each port can be associated with a specific process or service
  • Ports allow computers to differentiate between different kinds of traffic from the same IP address: emails go to a different port (25) than webpages (80), for instance, even though both reach a computer over the same Internet connection.
  • Some ports are reserved and some are open

Read more here

7 of 27

What is an http://127.0.0.1?

  • 127.0.0.1 is a special IP address – also referred to as “localhost” – which is a reference to your local computer.
  • Doesn't let computers communicate with other devices as a real IP address does (it’s private, not public)
  • On most operating systems, the following two addresses can be used interchangeably:

8 of 27

What is a web server

Web servers are services that are listening to HTTP traffic. They are constantly running (i.e., an infinite event loop) and listening to incoming traffic.

  • Web traffic (HTTP) is typically routed to port 80 (that’s a standard)
  • Encrypted web traffic (HTTPS) is typically routed to port 443 (that’s also a standard).

In Tutorial 11, you are going to create one of these web services that listens for traffic.

9 of 27

How does GitHub Pages work?

  • How does GitHub Pages work?
    • How do the files you push to GitHub end up on one of GitHub’s web servers?
  • What kinds of resources does GitHub Pages serve?
  • What kinds of resources does it not it serve?

10 of 27

Static Web Page

Architecture

(Homework 2)

11 of 27

Outline

  1. Services, hosts, and ports
  2. Databases
  3. Building a REST API

12 of 27

What is a database?

A database is an organized collection of structured information, or data, typically stored electronically in a computer system.

How is this better than just storing data in a text file?

13 of 27

Why would you want to use a database?

14 of 27

Why would you want to use a database?

  • Organizing your data: Strategies for grouping like entities together.
  • Enforcing data validation and integrity rules
  • Transaction management: if multiple people are altering the same data instance at the same time, the database will help organize these requests so that they don’t collide with each other
  • Indexing: Databases also have infrastructure for building binary search trees to speed up queries (so that searches can be done in O(logn) time).
  • SQL: Relational databases also understand SQL – a declarative language that allows a user to define the structure of a database, and to “CRUD” data.

15 of 27

Types of Databases

There are many different kinds of databases, but the two most common “families” of databases are:

  1. Relational Databases
  2. NoSQL Databases

16 of 27

Types of Databases: Relational (SQL) Databases

  • Approach: Data is organized into tables with predefined schemas, where rows represent records and columns represent fields.
  • Examples: PostgreSQL, Oracle, Microsoft’s SQL Server, MySQL, SQLite)
  • Strengths:
    • Ensures data integrity with transactions (ACID Compliance)
    • Structured Query Language (SQL): Industry standard for querying data.
    • Excellent at asking questions across multiple resources / collections. For instance: “which employees earned > $50K in revenue this week in under 40 hours?
  • Weaknesses:
    • Can be overkill for data that is fairly unstructured (e.g., storing chat messages, etc.)
    • Scalability: Hard to scale for very large datasets

17 of 27

Types of Databases: NoSQL Databases

  • Approach: A non-tabular database designed for flexibility, with different models (e.g., document, key-value, column-family, graph).
  • Examples: MongoDB, Firebase, CouchDB (document stores), Redis (Key-Value Stores, Neo4j (Graph databases)
  • Strengths:
    • Flexibility: Schema-less design allows storing unstructured and semi-structured data.
    • Scalability: Designed for distributed architectures.
    • Optimized for high-volume, low-latency operations.
  • Weaknesses:
    • Consistency: Availability over consistency
    • Limited support for complex queries across documents / resources.

18 of 27

Your REST API will use a database

You will be using SQLite to organize your data.

  • It’s a very simple database designed for learning and simple data organization and retrieval tasks
  • The entire database is stored in one file
  • You will be able to inspect your database directly from VS Code

19 of 27

Outline

  • Services, hosts, and ports
  • Databases
  • Building a REST API

20 of 27

Building a REST API

What kinds of things do we need to think about when building a REST API?

  • What resources are important?
  • What data fields should each resource have?
  • Who can access those resources (read / write)?
  • What should we name the endpoints?

21 of 27

Server-Side Architecture

22 of 27

Activity: Design an Online Shoe store

You are going to design an API blueprint for an online show store. Therefore, you’re going to have to make some decisions about:

  • What resources your system needs
  • What endpoints exist
  • What fields each endpoint needs
  • Which fields can be queried
  • Who is allowed to use each endpoint

23 of 27

Let’s keep it simple

This system can be complex, but let’s keep it simple by only designing allowing the user to interact with 3 Resources:

  • Sneakers
  • Favorites
  • Orders

24 of 27

Sneakers

  • Endpoint address: /api/sneakers
  • Data fields & types?
  • Which data fields are searchable?
  • Who should be able to see the data (the world, only some users)?

25 of 27

Favorites

  • Endpoint address:
  • Data fields & types?
  • Which data fields are searchable?
  • Who should be able to see the data (the world, only some users)?

26 of 27

Orders

  • Endpoint address:
  • Data fields & types?
  • Which data fields are searchable?
  • Who should be able to see the data (the world, only some users)?

27 of 27

Let’s build this thing!

npm install # installs dependencies

npm run generate # generates the API from the YAML file

npm run seed # inserts some fake data

npm run dev # starts the server

ngrok http 3100 # Sarah-only: share with the class…