Web Architecture & REST
CSCI 344: Advanced Web Technologies
Spring 2023
Announcements
Outline
Outline
Outline
Some terminology
What is a service?
On a Mac: lsof -i -P | grep -i "listen"
On a Windows: Control Panel > Administrator Tools > Service Icon
What is a port?
Copied directly from Cloudflare’s website:
Read more here
What is an http://127.0.0.1?
Outline
Recall from Week 6
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:
11
Who uses Web APIs?
Everyone!
Standardizing HTTP Interfaces
A variety of different solutions to this problem
Web APIs & the REST Architecture
One popular way of building a Web API is by following the REST architecture guidelines. Some facts about REST:
15
Resource-Oriented Architecture
16
1. Resource
Noun. The thing that is being represented by data / a document
17
Note the plural convention for detail resources
1. Resource
Example of a resource: https://csci344-hw07.herokuapp.com/api/posts/235
{
"image_url": "https://picsum.photos/600/430?id=908",
"user": {
"first_name": "Timothy",
"last_name": "Myers",
"username": "timothy_myers",� ...
},
"caption": "Spend catch ready administration success..."
"likes": 853
}
18
2. Addressability
19
2. Addressability: Examples
Container/List Resource (create and read):
�Detail Resource (update, delete):
20
3. Statelessness
Means that there is no “stored context” or memory across transactions:
21
4. Connectedness
You should be able to connect / discover relationships between resources from the resource representation. Example (Comment):
{
"text": "Text text text....",
"post_id": 6,
"user": {
"first_name": "Emily",
"last_name": "Terry",
"username": "emily_terry",
"email": "emily_terry@gmail.com",
...
}
}
22
5. Uniform Interface
“Interface” — refers to the way we interact with and modify resources.
�In REST All resources are created, updated, read, and deleted in the same way, using the HTTP protocol methods (verbs), which are defined in the header of the request. Here are some of them:
23
GET
Retrieves / reads a resource (or container of resources) from an address on a server
�NEVER modify a resource using the GET method – you can do it (technically) but you never should.
24
POST
Creates a NEW resource on a server; usually done by posting to the container endpoint:
25
PUT & PATCH
PUT: Replaces a single resource on a server
PATCH: Updates part of a resource on a server
26
DELETE
Permanently deletes a resource on a server
27
HTTP Status Codes
Use the status codes to help your client understand success and failure. Here is a list of them.
For HW1 and HW2...
References / Credits
Much of this REST overview was derived from:
RESTful Web Services�https://www.slideshare.net/cebartling/rest-web-services
29
Clients
You can access a REST API via many different clients (including):
Accessing Third Party Web APIs
Recall: Accessing a Web API
32
Passing data via a request using HTTP
There are several different ways that data can be passed TO a server via HTTP to formulate a request
Outline
Design a REST API for a Ticketing Service
You are designing a service to facilitate the purchase of tickets for various events (concerts, sporting events, plays, etc.). You need a way for your customers to browse various events, check out the venue, pick seats, and pay (ignore the login / registration workflow). Design a REST API to facilitate this.