An open API service indexing awesome lists of open source software.

https://github.com/codewithmayank-py/flask-api

Creating simple API using Flask
https://github.com/codewithmayank-py/flask-api

Last synced: 3 months ago
JSON representation

Creating simple API using Flask

Awesome Lists containing this project

README

        

# RESTful API Design with Python and Flask

## Overview
This project is a comprehensive demonstration of designing and developing RESTful APIs using the **Python Flask** framework. The goal is to cover fundamental and intermediate concepts of RESTful API design, ensuring the ability to create scalable and maintainable APIs.

## Tech Stack
- **Programming Language**: Python
- **Framework**: Flask
- **Libraries/Extensions**:
- `Flask-CORS` for handling Cross-Origin Resource Sharing (CORS)
- `Flask-Limiter` for implementing rate limiting and throttling
- `Flask` for developing the API and managing routes

## Project Structure
The project focuses on creating a RESTful API that simulates user and task management. Key features include CRUD operations, API versioning, security measures, and ensuring consistent API behavior through best practices like idempotency and error handling.

## Topics Covered
### 1. Creating API
- Developed endpoints for managing users and tasks.
- Implemented CRUD operations (`GET`, `POST`, `PUT`, `DELETE`).

### 2. API Security
- Integrated **HTTPS** for secure communication.
- Configured **CORS** to manage cross-origin requests.
- Applied **API rate limiting** to protect endpoints from misuse.

### 3. Rate Limiting and Throttling
- Implemented rate limiting to control the number of requests per user or IP.
- Introduced basic throttling to manage request bursts and ensure smooth traffic flow.

### 4. Idempotency
- Ensured idempotent behavior for `PUT` and `DELETE` methods, allowing multiple identical requests to have the same effect.
- Focused on maintaining consistent state in the API.

### 5. HATEOAS (Hypermedia As The Engine Of Application State)
- Embedded navigation links in API responses to guide clients through available actions.
- Enabled a more dynamic client interaction by providing links like `self`, `update`, `delete`, and `list` in responses.

### 6. Error Handling
- Standardized error responses using a consistent JSON structure.
- Utilized appropriate HTTP status codes (`404 Not Found`, `400 Bad Request`, `401 Unauthorized`, `429 Too Many Requests`).

### 7. Handling CRUD Operations
- Designed endpoints for `GET`, `POST`, `PUT`, and `DELETE` operations for managing user and task resources.
- Applied best practices for structuring and managing these operations.

### 8. Versioning
- Implemented **URI Versioning** to ensure backward compatibility.
- Added version information in the path (`/api/v1`) to manage evolving API changes without affecting existing clients.

## Getting Started
### Prerequisites
- Python 3.12.7 installed
- `Flask`, `Flask-CORS`, and `Flask-Limiter` libraries installed:

```bash
pip install Flask Flask-CORS Flask-Limiter
```
- Running the Project
```bash
git clone https://github.com/CodeWithMayank-Py/flask-api.git
```
- Navigate to the project directory
```bash
cd flask-api
```
- Run the Flask app:
```python
python app.py
```
- The API will be available at `http://127.0.0.1:5000`.

## Conclusion

This project serves as a solid foundation for building RESTful APIs using Flask, covering essential concepts and practices for API development. It provides the knowledge needed to design APIs that are secure, scalable, and maintainable, ready for real-world applications.

## Future Enhancements
- Extend the project with additional API versions `v2`, `v3` to demonstrate how to manage evolving API functionality.
- Integrate with a database like SQLite or PostgreSQL for persistent storage.
- Add user authentication using JWT (JSON Web Tokens) for enhanced security.

## Official Documentation
- [RESTful API Principles](https://restfulapi.net/)
- [Python Official Documentation](https://www.python.org/doc/)
- [Flask Official Documentation](https://flask.palletsprojects.com/)

## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.