Name | Progress |
---|---|
Introduction | Not Read |
π° Player | Not Read |
Name | Progress |
---|---|
Software Installation | Not Read |
Project Setup | Not Read |
Running and Testing | Not Read |
React and ReactDOM | Not Read |
π‘ Assignment 1: Welcome Message | Not Attempted |
Submissions | Not Read |
Name | Progress |
---|---|
JSX and Components | Not Read |
Props | Not Read |
πΎ Exercise: Props | Not Attempted |
CSS Styles | Not Read |
useState and Hooks | Not Read |
πΎ Exercise: useState | Not Attempted |
Conditional Rendering | Not Read |
Lists | Not Read |
πΎ Exercise: Lists | Not Attempted |
Forms and Events | Not Read |
πΎ Exercise: Forms | Not Attempted |
π‘ Assignment 2: Front End | Not Attempted |
Name | Progress |
---|---|
Pure Components - memo | Not Read |
Lifecycle - useEffect | Not Read |
Expensive? - useMemo | Not Read |
DOM Interactions - useRef | Not Read |
forwardRef | Not Read |
useImperativeHandle | Not Read |
πΎ useImperativeHandle | Not Attempted |
Context | Not Read |
useCallback | Not Read |
useId | Not Read |
useReducer | Not Read |
Name | Progress |
---|---|
Database | Not Read |
NextAuth and Github Authentication | Not Read |
Prisma and ORM | Not Read |
Project Setup | Not Read |
Project Authentication | Not Read |
Name | Progress |
---|---|
tRPC | Not Read |
tRPC - Routers | Not Read |
tRPC - Server Rendering | Not Read |
tRPC - Client Rendering | Not Read |
Persisting Data | Not Read |
Assignment 3: APIs | Not Read |
REST APIs, or Representational State Transfer Application Programming Interfaces, are a popular way to create web services that communicate over HTTP. They are designed to be simple, stateless, and resource-based, making them an efficient way for different software systems to exchange data. Let's explore what REST APIs are, why they are widely used, and how to work with them through examples.
Statelessness: Every request from a client to the server must contain all the information needed for the server to fulfill it. The server does not retain any session information between requests, making REST APIs scalable.
Uniform Interface: The API should have a consistent and predictable structure. REST uses standard HTTP methods like GET, POST, PUT, and DELETE, each mapping to a particular operation.
Resource-Based: The main concept of REST is that it treats everything as a resource (users, products, posts) that can be uniquely identified via a URL (Uniform Resource Locator).
Client-Server Architecture: The client (frontend) and server (backend) are separate entities that communicate via the REST API, allowing independent development and scaling.
GET: Retrieve data from the server.
POST: Submit new data to the server.
PUT: Update existing data or create new data.
DELETE: Remove existing data.
To illustrate how REST APIs work, let's consider a simple scenario where we manage a list of books.
Retrieve a list of all available tasks:
GET https://api.example.com/tasks
Response (JSON):
[
{"id": 1, "title": "Clean the room"},
{"id": 2, "title": "Cook a dinner"}
]
Retrieve a specific task by its ID:
GET https://api.example.com/task/1
Response (JSON):
{
"id": 1,
"title": "Clean the room",
"due": "1/4/2024",
"state": "INCOMPLETE"
}
Add a new task to the list. The POST requests allow you to provide a body (payload) with data. The Post request then generates a response.
POST https://api.example.com/books
Request Payload (JSON):
{"title": "Wash a car" }
Response: A response indicating success, along with the newly created resource ID:
{"id": 3, "message": "Task added successfully"}
Update an existing book's information: PUT also allows to provide a request body (payload)
PUT https://api.example.com/books/1
Request Payload (JSON):
{"id": 3, "status": "COMPLETED"}
Response:
{"message": "Task updated successfully"}
Remove a task from the list:
DELETE https://api.example.com/books/1
Response:
{"message": "Book deleted successfully"}
Scalability: Statelessness ensures that the server doesnβt need to remember previous requests, allowing horizontal scaling.
Interoperability: By using standard HTTP methods, REST APIs can be consumed by any client, regardless of platform or programming language.
Maintainability: Uniform interfaces and consistent structure make REST APIs easier to document and maintain.
While REST APIs are highly popular and provide many benefits, they also have some drawbacks that developers should be aware of when choosing an API architecture. Here are a few notable limitations:
Overfetching and Underfetching:
Overfetching occurs when a client receives more data than it needs in response to an API call. For example, requesting an entire user object might also return fields that aren't necessary for the current task.
Underfetching happens when an API call does not return all required information, forcing the client to make multiple requests to get the complete data.
Type Safety
The APIs do impose a specific format of inputs and outputs. But, the client does not learn about any change until an error occurs. Thus, it would be better to have a mechanism that would allow for knowing, how any API change affects existing codebase.
Statelessness Limitations:
While statelessness makes scaling easier, it also requires that each request contains all the information needed for processing. This can lead to larger payloads and increase the number of requests if the same data is required repeatedly.
Lack of Flexibility in Data Queries:
REST APIs rely on fixed endpoints, which makes it difficult to retrieve data in complex or nested structures. In cases where clients need to customize their data queries dynamically, this lack of flexibility can be problematic.
Performance Issues:
Multiple Round Trips: Clients often need to call multiple endpoints to gather related data, resulting in additional network round trips and increased latency.
Heavy Payloads: Depending on the complexity of the resource, responses can be bulky, slowing down network transmission and increasing processing times
REST APIs offer a flexible and efficient way to connect different systems over the web. By understanding their principles and practicing the usage of HTTP methods and endpoints, you can design, implement, and consume REST APIs to build powerful applications that interact smoothly with other services.