1 of 30

Client-Server Communication over HTTP

CSCI 338: Software Engineering

Fall 2026

1

2 of 30

Agenda

  • Intro to Web Services and Web APIs
  • Intro to HTTP
  • Interacting with a REST APIs
  • Intro to the JavaScript fetch API
  • Summary

2

3 of 30

Outline

  1. Intro to Web Services and Web APIs
  2. Intro to HTTP
  3. Interacting with a REST APIs
  4. Intro to the JavaScript fetch API
  5. Summary

4 of 30

Understanding how to work with Web Services & APIs is so useful!

  • Many organizations make their data, storage, and compute services available over the web.
  • Understanding how to interact with various web services using the HTTP protocol is perhaps one of the most useful, practical skills that you can learn.
  • This isn’t just relevant for web browsers – all modern programming languages have a way to encode, decode, and communicate messages over HTTP.

5 of 30

What is a Web API?

API → “Application Programming Interface”

A set of rules that you have to follow to interact with a piece of software

​

Web API

An API that you access via HTTP protocol. Offers a systematic way to:

  1. Create update, read, and delete resources over the internet
  2. Expose parts of your database to third party clients
  3. Allow a web client (or any client) to take advantage of resources distributed across providers, servers, organizations, etc.

​

REST API

A kind of Web API that honors the “REST” endpoint design conventions

5

6 of 30

Many Organizations Publish their Data via Web APIs

  • Companies:
    • e.g., Spotify, Yelp, OpenAI, etc.
  • Government Organizations:
    • e.g., NASA, Asheville Open Data Portal, etc.

7 of 30

Outline

  1. Project 1 Feedback
  2. Intro to Web Services and Web APIs
  3. Intro to HTTP
  4. Interacting with Web / REST APIs
  5. Intro to the JavaScript fetch API
  6. Summary

8 of 30

HTTP: Hypertext Transfer Protocol

Web servers communicate through HTTP – a stateless protocol for encoding, decoding, and transmitting messages over the web.

  • Stateless mean that no memory is preserved between requests – each request must contain all the information needed on its own to fulfill the request (no stored context).
  • HTTP requests and responses have a header (which contains metadata about the request) and a body (which contains the request itself)
  • HTTP requests also have methods (GET, POST, PATCH, PUT, DELETE, etc.) – next slide.
  • HTTP responses have status codes that tell you whether the request was successful or not.

8

9 of 30

HTTP Methods

Methods tell the server what action they should take (verbs):

9

Method

Job

Description

GET

Read

Retrieves / reads a resource (or container of resources) from an address (endpoint) on a server

POST

Create

Creates a NEW resource on a server; done by posting data to an address (endpoint) on a server

PUT

Replace

Replaces a resource on a server

PATCH

Update

Updates a resource on a server

DELETE

Deletes

Deletes a resource on a server

10 of 30

HTTP Status Codes

Status codes provide information re: whether your request was successful. Here is a list of them. Ones you should be familiar with:

Code

Definition

201

POST method successfully created a resource

200

Valid request made (generic success message)

400

Client posted a bad request that the server can’t understand

403

Forbidden (you don’t have access to it)

404

Resource cannot be found

500

Server error (usually because there’s a server bug)

11 of 30

Outline

  1. Intro to Web Services and Web APIs
  2. Intro to HTTP
  3. Interacting with Web / REST APIs
  4. Intro to the JavaScript fetch API
  5. Summary

12 of 30

Interacting with a Web / REST API: Clients

You can access a REST API via many different clients (including):

  1. Through your browser
  2. Through Java, C, C++, Python, or any other language
    1. In other words, servers talk to other servers via HTTP/S requests
  3. cURL or wget (command line tools)
  4. Postman
  5. And more!

13 of 30

13

PostgreSQL

FastAPI (python service) +�SQLAlchemy �Listening on port 80 / 443

Client Machine

(phone, laptop, tablet)

Curl

Python Script

Web �Browser

Public Address, Allows Connections From Anywhere

VIEW

MODEL + CONTROLLER

DATABASE

14 of 30

Demo �class-exercises-fall2026/fastapi_demo

14

15 of 30

Sync Fork, Pull Down, Make a new Branch

  • Sync fork to pull latest changes
  • If applicable: stage and commit your current work on your current branch
  • Checkout main
  • pull
  • Create a new branch called fastapi-exercise-b
  • Open the fastapi_demo folder in your code editor

15

16 of 30

Exercises: cURL

  1. On your command line, navigate to fastapi_demo/ui/samples
  2. Let’s start with bash:
    • cd into samples_bash
    • Open 01_create.sh
    • Change the root url to my server (instead of localhost):�____________________________
    • Run the script: bash 01_create.sh
    • What happened?
  3. Change the root url to my server (instead of localhost):�https://b6d5-2600-6c5e-56f0-d780-6875-1742-ff20-df68.ngrok-free.app/todos

16

17 of 30

Exercises: JavaScript Client

  1. On your command line, navigate to fastapi_demo/ui/samples
  2. Let’s start with python:
    • cd into samples_javascript
    • Open 01_create.js
    • Change the root url to my server (instead of localhost):�____________________________
    • Run the script: node 01_create.js
    • What happened?

17

18 of 30

Exercises: Python Client

  1. On your command line, navigate to fastapi_demo/ui/samples
  2. Let’s start with python:
    • cd into samples_python
    • Run poetry install
    • Open 01_create.py
    • Change the root url to my server (instead of localhost):�https://b6d5-2600-6c5e-56f0-d780-6875-1742-ff20-df68.ngrok-free.app/
    • Run the script: poetry run python 01_create.py
    • What happened?

18

19 of 30

Takeaway

  • So long as a server’s port is open and accepting connections, any machine in the world can communicate with it.
  • As noted earlier, one of the primary ways that applications communication with servers is using the HTTP protocol:
    • Server: “My PORT 80 is open, and I’m allowing HTTP connections to interact with my database, using my REST API”

19

20 of 30

Outline

  1. Intro to Web Services and Web APIs
  2. Intro to HTTP
  3. Interacting with a REST APIs
  4. Intro to the JavaScript fetch API
  5. Summary

21 of 30

OK! So how do I get my React App (written in JavaScript + a few additional bells and whistles) �to communicate with a server?

21

22 of 30

23 of 30

Intro to Fetch

JavaScript’s Fetch API

  • The Fetch API is a newer API for browsers to communicate asynchronously with servers communication (improving upon AJAX – the older way)
  • Because this API allows for asynchronous, non-blocking communication with servers, promises were introduced to the JavaScript Language.
  • Promises are objects that help programmers manage asynchronous communications.

​

23

24 of 30

What is a Promise?

  • Promises exist to handle asynchronous functionality
  • It allows you to put a process on the “back burner” until it completes…and in the meantime your browser is free to do other things.
  • When the request completes, you are notified, and can proceed with any functionality that depends on the request completing.
  • Uses the async / await keyword pairs.

25 of 30

Most requests happen in 2 Parts (w/2 Promises)

async function getData () {

const response = await fetch(url); // returns a promise

const data = await response.json(); // returns a promise

}

  • fetch() returns a promise containing the response (a Response object). This is just an HTTP response, not the actual content.
  • To extract the body content from the response, we use one of the response’s content methods – in this case the json() method – which also returns a promise with the actual data.

26 of 30

Outline

  1. Intro to Web Services and Web APIs
  2. Intro to HTTP
  3. Interacting with a REST APIs
  4. Intro to the JavaScript fetch API
  5. Summary

27 of 30

Summary (1 of 2)

  1. Web services / REST APIs allow an organization to make their data, storage, and computing services available over the web via a web server.
    1. You interact with them via HTTP requests that specify actions via methods (GET=read, POST=create, PATCH=update, PUT=replace, DELETE=delete, etc.)
    2. You often need to authenticate with them by including an API key in the header of the HTTP request.
    3. Every web service is different – you need to read the provider’s documentation to understand how to use their service.
    4. Lots of different clients can make HTTP requests (e.g., web browser, most programming languages, PostMan, the command line, etc.)

28 of 30

Summary (2 of 2)

  1. You can interacting with a Web service in most modern programming languages
  2. In JavaScript, you can interact with a server by using the browser’s fetch API and promises.
    1. The fetch API allows you to issue HTTP requests
    2. Promises allow you to be able to handle asynchronous requests
    3. The async / await keywords allow you to create functions that can pause code execution until the promise resolves.

29 of 30

Activity: Integration with React

29

30 of 30

React + Data

Set-up:

  1. Navigate into fastapi_demo/ui
  2. Install the dependencies: npm install
  3. Start the bundler / hot reloading service: npm run dev
  4. Navigate to http://localhost:5173/

Check out the ui/src directory and take a look at the components

  1. Import the Todos component into App and invoke it (by adding a <Todos /> tag).

30