தமிழ்: REST API Tutorial & Examples | InterviewDOT

Learn REST API concepts with Tamil tutorials & Spring demo. Get code on GitHub & stay updated with notifications! 🚀

தமிழ்: REST API Tutorial & Examples | InterviewDOT
Interview DOT
98.8K views • Aug 10, 2019
தமிழ்: REST API Tutorial & Examples | InterviewDOT

About this video

Click here - https://www.youtube.com/channel/UCd0U_xlQxdZynq09knDszXA?sub_confirmation=1 to get notifications. REST API SPRING DEMO :

Code Github - https://github.com/net-vinothkumar/springrestapi

SPRING REST API DEMO :

What is REST API ?

An architectural style called REST (Representational State Transfer) advocates that web applications should use HTTP.

GET - http://localhost:8080/SpringBootRestApi/api/employee/
POST - http://localhost:8080/SpringBootRestApi/api/employee/

{
"name": "Johnson",
"age": 30,
"salary": 90000
}
PUT - http://localhost:8080/SpringBootRestApi/api/employee/4

{
"name": "Todd",
"age": 50,
"salary": 50000
}

DELETE - http://localhost:8080/SpringBootRestApi/api/employee/5

Every Resource is Identified by a Unique Identifier (URI)
Stateless (every request happens in complete isolation, it's easier to cache and load-balance)

### REST API and CRUD Operations

A **REST API** (Representational State Transfer Application Programming Interface) is a powerful tool for building web services that allow systems to communicate over HTTP. It is widely used for creating scalable, maintainable, and stateless applications. One of the foundational concepts in REST APIs is **CRUD operations**—the basic actions for interacting with data.

---

### **What is a REST API?**
A REST API follows a set of architectural principles that define how web services should interact:
1. **Stateless Communication:** Each request from a client contains all the information needed to process it.
2. **Uniform Interface:** Uses HTTP methods and standard URIs for consistency.
3. **Client-Server Separation:** Frontend and backend systems are decoupled, allowing for independent development.
4. **Resource Representation:** Data is presented in formats like JSON or XML.

---

### **CRUD Operations in REST API**
CRUD refers to the four fundamental operations used to manage resources in a system:
- **Create**
- **Read**
- **Update**
- **Delete**

These operations map directly to HTTP methods in a REST API:

---

### **1. Create**
- **HTTP Method:** `POST`
- **Purpose:** Add a new resource to the server.
- **Example Endpoint:**
- URL: `/users`
- Request:
```json
{
"name": "John Doe",
"email": "john@example.com"
}
```
- Response:
```json
{
"id": 1,
"name": "John Doe",
"email": "john@example.com"
}
```

---

### **2. Read**
- **HTTP Method:** `GET`
- **Purpose:** Retrieve data from the server.
- **Example Endpoints:**
- Get all resources: `/users`
- Get a single resource by ID: `/users/1`
- **Response:**
```json
{
"id": 1,
"name": "John Doe",
"email": "john@example.com"
}
```

---

### **3. Update**
- **HTTP Method:** `PUT` or `PATCH`
- `PUT`: Updates the entire resource.
- `PATCH`: Updates part of the resource.
- **Purpose:** Modify an existing resource on the server.
- **Example Endpoint:**
- URL: `/users/1`
- Request:
```json
{
"email": "john.doe@example.com"
}
```
- Response:
```json
{
"id": 1,
"name": "John Doe",
"email": "john.doe@example.com"
}
```

---

### **4. Delete**
- **HTTP Method:** `DELETE`
- **Purpose:** Remove a resource from the server.
- **Example Endpoint:**
- URL: `/users/1`
- **Response:**
```json
{
"message": "User deleted successfully"
}
```

---

### **Best Practices for REST APIs and CRUD**
1. **Use Resource Naming Conventions:**
- Use plural nouns: `/users`, `/products`.
- Avoid verbs in URLs.

2. **Implement Status Codes:**
- `200 OK`: Successful requests.
- `201 Created`: Resource created.
- `404 Not Found`: Resource not found.
- `400 Bad Request`: Invalid input.

3. **Stateless Design:**
- Keep requests independent to ensure scalability.

4. **Paginate Large Data Sets:**
- Example: `/users?page=1&limit=20`.

5. **Secure API Endpoints:**
- Use authentication methods like OAuth or API keys.

---

### **Benefits of Using REST API with CRUD**
- **Scalability:** Stateless architecture makes it easier to scale services.
- **Flexibility:** CRUD operations map seamlessly to most database functions.
- **Interoperability:** REST APIs can be consumed by any client, irrespective of the technology stack.

By mastering REST APIs and CRUD operations, developers can build robust and efficient systems that are foundational to modern web development.

Tags and Topics

Browse our collection to discover more content in these categories.

Video Information

Views

98.8K

Likes

1.5K

Duration

14:07

Published

Aug 10, 2019

User Reviews

4.7
(19)
Rate:

Related Trending Topics

LIVE TRENDS

Related trending topics. Click any trend to explore more videos.