1/153
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What web application are not limited to other than delivering static html page
They need to send and receive data between the browser (or another client) and the server in the real time
Define web api
Interact that allows allows different software and application to communicate and exchange data over the web, typically using HTTP
What does Web api typical use?
Http
What does web api provide clearly define
A way for clients to request, modify and work with application data
What are some clients examples
Web browsers, mobile apps, smartwatch apps, other server
How do you design these app effectively as a developer
Using REST
What does REST stand for
REpresentational State Transfer
What is REST
A guiding principle when designing app
What is not rest
a protocol, format, or strict rulebook
What does Restful API principle follow
The three main prince-Les of how web component should interact with the internet
How many main principals is there
3
What are those 3 principals
Stateless communication, Resource based structure, Use of HTTP method
What is stateless communication
Every request is independent and contains all the information the
server needs.
What is Resource based structure
data and functionality are organized into distinct resources, each with a unique URL.
What is Use of HTTP method
Standard HTTP verbs indicate the desired actual on the resource
What are some HTTP verbs
GET, POST, PUT, DELETE
HOWS DOEs a restful web API presents all the server available resource
Clear and structure way
What is the RESTFUL web API presenting
Al, the server available resource
What happens after a RESTFUL web API presents the available resource in the server?
Making it a obvious way clients can access and how to interact with them
How is each resource defined
By a unique url
How can the resource be mani-ukated
Using standard HTTP methods
What are some form resources can take on
JSON, HTML, PLAIN TEXT/XML, images, videos, or other files
Why would a resource take a form of a JSON
Structured data exchange
Why would a resource take a form of a HTML
For web pages
Why would a resource take a form of a Plain text / xml
For simpler or legacy data formats
Why would a resource take a form of a images, videos, or other files
For media content
What do some resource require
Authentication or permission to access certain data
the APIâs structure and available endpoints are fully _____
Visible
What are the benefits of having api structure and available endpoints fully visible for the clients
Clients can see what is possible even if they canât access everything
What clarity would be provided having api structure and available endpoints fully visible for the developer
helps developers understand the system,
know which actions are allowed, and integrate with it reliably
In a restful api what is presented as resource
Data
In a restful api what can you do to data presented as resource
Created retrieved update delete
What is the operation collectively called when you create, retrieved, update, delete resources
CRUD
What does the C stand and whatâs the operation performed in crud
Create A resource - Post request
What does the R stand and whatâs the operation performed in crud
Read A resource - get request
What does the U stand and whatâs the operation performed in crud
Update A resource - put or patch request
What does the D stand and whatâs the operation performed in crud
delete A resource - Delete request
In a RESTful API for a site with songs, what would be the method, url and request if I want to get a list of all songs
Get, /songs, 200 OK
In a RESTful API for a site with songs, what would be the method, url and request if I want to get all rock songs from 202
Get, /songs?genre=rock&year=2020, 200 OK
In a RESTful API for a site with songs, what would be the method, url and request if I want to get a songs with ID 202
Get, /songs/202, 200 OK
In a RESTful API for a site with songs, what would be the method, url and request if I want to get lyrics for songs with ID 202
Get, /songs/202/lyrics, 200 OK
In a RESTful API for a site with songs, what would be the response if I want to get a non existing songs with ID 0
404 not found
In a RESTful API for a site with songs, what would be the method, url and request if I want to create a new song
Post, /songs, 201 created
In a RESTful API for a site with songs, what would be the method, url and request if I want tp update song with 202
PUT, /songs/202, 204 no content
In a RESTful API for a site with songs, what would be the method, url and request if I want tp update song with 202
Delete, /songs/202, 204 no content
In a RESTful API for a site with songs, what would be the method, url and request if I want tp get top 10 songs
Get, /songs/top?limit=10, 200 OK
In a RESTful API for a site with songs, what would be the method, url and request if I get all songs by artist with id 45
Get, /artist/45/songs, 200 OK
Whats are the six architectural constrains to a truly designed RESTful API
Client-server, stateless, cacheable, uniform interface, layered system, code on demand (optional)
Does the client and server share or separate responsibilities
seperate responsibilities
Why does the client and server have separate responsibilities
So changes doesnât affect each other
What is server duties
Store the data, rules, and logic, and provide information (rep of resort Ed) in response to client requests
What is client duties
Makes requests to the server and does something useful with the response.
How does the client and server see each other
Black boxes
What does it mean when the client and server see each other as Black boxes
where each knows the API (the
interface) but not the internal implementation of the other
In some cases, what may the client learn
the client learn the API dynamically from the server
What benefit does this separation Between the client and server provide
Flexibility
What can different types of clients do with the same server
Interact
What comprises does the server have when changing how it stores or manage data
Thereâs no disadvantages it doesnât affect the client
Will adding New components or services disrupt the system
No
IN rest, what does each request from the client include and what is done with that item
information the server needs to process it and respond
What memory does the server keep of the previous request or client session state
None
Why does the server doesnât keep any memory of previous requests or client
session state
treats every request as independent
Why itâs better treating every request as independent
Easier to add more server to handle additional requests, which improves scalability
Imagine a product search: GET /products?type=book . The server might return only the first 10 results. What would we do if we want more.
We must include all the necessary information to get the next set such as
GET /products?type=book&start=25
GET /products?type=book&page=2
GET /products?type=book&limit=25&offset=25
What is the difference between non-restful system and restful system when handling servers
non-RESTful systems often rely on server-side session state. The server
remembers what the client was doing, allowing requests like:
GET /products?type=book
GET /nextPage
GET /nextPage
We have a non restful request,
GET /products?type=book
GET /nextPage
GET /nextPage
What rule does this violate?
Statelessness, server keeps track of the clientâs progress
We have a non restful request,
GET /products?type=book
GET /nextPage
GET /nextPage
What would happen if it crashes and compare this to stateless system.
server crashes, the client may lose its session and have to start over. A stateless system, on the other hand, is more robust and scalable
Since each request contains all the information the server needs, how many requests can the server handle
Any
What would happen to stateless system if one server fail.
another can take over without interrupting the clientâs interactions.
What does A REST server explicitly indicate
A response can be cached
How is cache headers done in REST
Using HTTP headers (Cache-Control or Expires)
If a response is cacheable, what can the server also specify
How long itâs remains valid
What happens when a client has a valid cached copy
it can reuse it instead of making a new
request
What are the benefits of reusing a valid cache copy
reduces network traffic and server load. Making the system more scalable
and efficient.
consider an image-hosting website. The server stores both images and metadata (e.g., filename, upload date, tags, or description). While metadata may change, the image files themselves usually do not.
How will the server can mark the images and metadata and what are the benefits of doing this.
Images as cacheable for longer periods, while metadata may have shorter cache times or no caching at all. Clients and intermediaries can reuse large, unchanging resources efficiently
What are the benefits of RESTful system using a uniforms interface for the API
predictable, easy to understand, and interoperable across different systems
What are the key aspects of RESTFUL system uniform interface
Identification of Resources, Manipulation of resources through representations, Self-descriptive message, HATEOAS
REST is centered around resources, which are any entities that can be named< what are some of those examples
images, user profiles, orders, or real-time data streams
How are resources created and how are they identified
dynamically generated by the server and uniquely identifiable by a URL that remains constant for its lifetime
Do urls represent nouns or verb?
Nouns
What happen if an API use verbs in the url such as /removeProduct or /updateProduct
Generally are not RESTFUL
In Rest what does the client interacts with the resource
The information, not the resource itself ir it storage mechanism
How is this information formatted in REST when the client interacts with the information and why
JSON and contains all the data needed to understand and work with it
What does the server handle in regards to Manipulation of resources through representations
The actual storage and management of the resource (e.g., by using a database, files, or even other servers)
Does the client need to know how it done when the server handles the storage and the management of the resource? And why?
No as this separation allows the server to
change its internal implementation without affecting the client
What does the client and server do after receiving the resource information
Display the product or let a user interact
with it. The server may later change its internal storage (e.g., move from a database to a file system), but the client still receives the same JSON format, so its code doesnât break.
In a RESTful system, every request and response should contain enough of what
information to be understood on its own, without relying on previous messages.
In a RESTful system, every message should contain ____ type? And why
each message should contain a data type, which tells the receiver what kind of data it is receiving (e.g., "Content-Type" in HTTP).
Why should RESTFUL system follow the formal meaning of the HTTP verbs
Because these verbs have well-known meanings, clients and servers can interact consistently, which contributes to a uniform interface
What does HATEOAS stand for
Hypermedia As The Engine Of Application State
What does hypermedia links in the server response act in REST and why
Signpost. The client doesnât need to âknowâ all URLs in advance; it can simply follow the links provided by the server
Where can the client start to discover and navigate other resources dynamically using hyperlinks?
An inital url
What are the benefits of HATEOAS approach in the client side
Explore relationship(e.g., how a product is linked to its reviews or manufacturer), discover related resources (e.g., similar products), and interact with the system without hardcoding any URLs.
What would be a example of HATEOAS for both client and sever side
a client requests the first page of products like this: GET /products
The server can respond with JSON including products and links:
{
"products": [
{ "id": 101,
"name": "Wireless Mouse",
"price": 29.99,
"links": {
"reviews": "/products/101/reviews"
,
"similar": "/products?category=accessories" }},
{ "id": 102,
"name": "Mechanical Keyboard",
"price": 79.99,
"links": {
"reviews": "/products/102/reviews",
"similar": "/products?category=keyboards" }}],
"links": {
"nextPage": "/products?start=10" }
From this server JSOn file, how would you see reviews for the mouse
{
"products": [
{ "id": 101,
"name": "Wireless Mouse",
"price": 29.99,
"links": {
"reviews": "/products/101/reviews"
,
"similar": "/products?category=accessories" }},
{ "id": 102,
"name": "Mechanical Keyboard",
"price": 79.99,
"links": {
"reviews": "/products/102/reviews",
"similar": "/products?category=keyboards" }}],
"links": {
"nextPage": "/products?start=10" }
To see reviews for the mouse, the client follows /products/101/reviews, to see similar products it follows /products?category=accessories, to see the next page of products it follows /products?start=10
For fully RESTful systems that implement HATEOAS, does the client hardcode url
No it discovers all actions dynamically through the links provided in the responses
Why donât REST API fully use hypermedia content often
APIs still expect the client to know URLs in advance and donât provide hypermedia links
For fully RESTful systems that implement HATEOAS, are they considered RESTful even if they use HTTP verbs and URL
No
In REST, the system can be composed of multiple layers of servers or services it the client interact with what as a whole
the system as a whole and never needs to know how many layers exist or how they are structured