Drawer

API Understanding

What is an API?

API (Application Programming Interface) is a way for two software systems to talk to each other.

Think of it like a restaurant 🍽️

  • You = client (frontend / app)

  • Kitchen = server (database / backend)

  • Waiter = API

You ask for food → waiter takes request → kitchen prepares → waiter brings response.

In tech terms:

  • You send a request

  • API processes it

  • API sends back a response (data)

🔁 What is a RESTful API?

REST (Representational State Transfer) is a set of rules for building APIs in a clean, standard way.

A RESTful API:

  • Uses HTTP methods

  • Works with URLs

  • Sends data usually in JSON

  • Is stateless (each request is independent)

🚦 HTTP Methods (Very Important) Method Meaning Example GET Read data Get users POST Create data Add a user PUT Update data Edit a user DELETE Remove data Delete a user 📍 REST API Example   GET /users → get all users GET /users/1get user with ID 1 POST /users → create new user PUT /users/1update user 1 DELETE /users/1delete user 1 🧠 Why RESTful APIs are popular?
  • Simple & predictable

  • Easy to use with frontend (React, mobile apps)

  • Scalable

  • Works over the internet using HTTP

Python Version: Simple REST API using Flask 🔧 Requirements
  • Python 3.x

  • Flask

Install Flask   pip install flask 📁 Project Structure   student_api/ ├── app.py └── README.txt (optional) 📌 app.py (Python Flask REST API)   from flask import Flask, jsonify, request app = Flask(__name__) # Fake database students = [ {"id": 1, "name": "Alice", "age": 20}, {"id": 2, "name": "Bob", "age": 22} ] # GET all students @app.route("/students", methods=["GET"]) def get_students(): return jsonify(students) # GET student by ID @app.route("/students/<int:id>", methods=["GET"]) def get_student(id): student = next((s for s in students if s["id"] == id), None) return jsonify(student) # POST new student @app.route("/students", methods=["POST"]) def add_student(): data = request.get_json() new_student = { "id": len(students) + 1, "name": data["name"], "age": data["age"] } students.append(new_student) return jsonify(new_student) # DELETE student @app.route("/students/<int:id>", methods=["DELETE"]) def delete_student(id): global students students = [s for s in students if s["id"] != id] return jsonify({"message": "Student deleted"}) if __name__ == "__main__": app.run(debug=True) 🧪 Testing the API

Use Postman or browser:

  • GET http://127.0.0.1:5000/students

  • GET http://127.0.0.1:5000/students/1

  • POST http://127.0.0.1:5000/students

  { "name": "Charlie", "age": 21 }
  • DELETE http://127.0.0.1:5000/students/1

📘 COLLEGE PROJECT REPORT 🏷️ Title Page

Project Title:
Understanding APIs and RESTful APIs using Python (Flask)

Submitted By:
(Your Name)

Course:
(Your Course Name)

Institution:
(College Name)

Academic Year:
(Year)

📄 Abstract

This project focuses on understanding Application Programming Interfaces (APIs) and RESTful APIs by designing and implementing a simple REST API using Python Flask. The project demonstrates how data can be exchanged between a client and server using HTTP methods such as GET, POST, and DELETE.

📚 1. Introduction

In modern web development, APIs play a crucial role in enabling communication between different software systems. RESTful APIs are widely used because they are simple, scalable, and platform-independent. This project aims to provide a basic understanding of APIs and REST architecture through hands-on implementation.

🌐 2. What is an API?

An API (Application Programming Interface) allows different software applications to communicate with each other. It acts as an intermediary that receives requests and returns responses in a structured format, usually JSON.

🔁 3. What is a RESTful API?

REST (Representational State Transfer) is an architectural style for designing networked applications. A RESTful API uses standard HTTP methods and URLs to perform CRUD (Create, Read, Update, Delete) operations.

REST Principles:
  • Stateless communication

  • Client-server architecture

  • Resource-based URLs

  • Use of HTTP methods

🚦 4. HTTP Methods Used Method Description GET Retrieve data POST Create new data DELETE Remove data 🛠️ 5. Tools and Technologies
  • Programming Language: Python

  • Framework: Flask

  • Data Format: JSON

  • Testing Tool: Postman / Browser

🧩 6. Project Description

The project implements a Student Management REST API that allows users to:

  • Retrieve all students

  • Retrieve a student by ID

  • Add a new student

  • Delete an existing student

The API stores data in a temporary in-memory list, simulating a database.

⚙️ 7. System Implementation

The Flask framework is used to define routes and handle HTTP requests. Each endpoint corresponds to a specific operation and returns JSON responses.