├── README.md └── main.py /README.md: -------------------------------------------------------------------------------- 1 | # Flask API Integration 🚀 2 | 3 | 4 | ### Table of Contents 📑 5 | 6 | - [Introduction 🚀](#introduction) 7 | - [Project Details: 💻🌐📅✍️](#project-details-%EF%B8%8F) 8 | - [Description](#description) 9 | - [Installation 🛠️](#installation-️) 10 | - [Usage 🚀](#usage-) 11 | - [API Endpoints 🌐](#api-endpoints-) 12 | - [Contributions 🌟](#contributions-) 13 | - [License 📜](#license-) 14 | 15 | --- 16 | 17 | ## Introduction 18 | 19 | Welcome to the Flask API Integration project! This simple Flask application taught by **Shreya Malogi** demonstrates basic API integration using the Flask framework. 20 | 21 | [![GitHub stars](https://img.shields.io/github/stars/shreyamalogi/flask-api-integration.svg?style=social)](https://github.com/shreyamalogi/flask-api-integration/stargazers) 22 | 23 | ### Project Details: 💻🌐📅✍️ 24 | 25 | - **Functionality:** Demonstrates basic API integration using Flask. 26 | - **Tech Stack:** `Flask`, `Python` 27 | - **Author:** [@shreyamalogi](https://github.com/shreyamalogi/) 28 | - **Year of Project:** 2022 29 | 30 | --- 31 | 32 | ## Description 33 | 34 | Flask API Integration is a beginner-friendly project showcasing API integration using the Flask framework. The application provides two endpoints: the home page and a user-specific page. Each endpoint returns a JSON response indicating the successful loading of the respective page. 35 | 36 | ## Installation 🛠️ 37 | 38 | 1. Install Flask: 39 | 40 | ```bash 41 | pip install flask 42 | ``` 43 | 44 | 2. Run the application: 45 | 46 | ```bash 47 | python .py 48 | ``` 49 | 50 | Replace `` with the name of your Python file. 51 | 52 | ## Usage 🚀 53 | 54 | - **Home Page:** Access the home page at `http://localhost:2000/` to receive a JSON response indicating the successful loading of the home page. 55 | 56 | - **User Request:** Access the user page at `http://localhost:2000/user/?user=` to receive a JSON response indicating the successful loading of a user-specific page. Replace `` with the desired username. 57 | 58 | ## API Endpoints 🌐 59 | 60 | 1. **Home Page:** 61 | - Endpoint: `http://localhost:2000/` 62 | - Method: `GET` 63 | - Response Format: JSON 64 | - Sample Response: 65 | ```json 66 | { 67 | "page": "Home", 68 | "Message": "successfully loaded the home page", 69 | "Timestamp": 70 | } 71 | ``` 72 | 73 | 2. **User Request:** 74 | - Endpoint: `http://localhost:2000/user/?user=` 75 | - Method: `GET` 76 | - Parameters: 77 | - `user`: The username for which the request is made. 78 | - Response Format: JSON 79 | - Sample Response: 80 | ```json 81 | { 82 | "page": "request", 83 | "Message": "successfully loaded the request for pages", 84 | "Timestamp": 85 | } 86 | ``` 87 | 88 | ## Contributions 🌟 89 | 90 | Contributions are welcome! If you find any issues or have suggestions, feel free to create a pull request or open an issue. 91 | 92 | ## License 📜 93 | 94 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. 95 | 96 | © 2022 Shreya Malogi 97 | 98 | Happy Coding! 🚀👩‍💻 99 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from email.policy import default 2 | from flask import * 3 | import json, time 4 | 5 | app = Flask(__name__) 6 | 7 | @app.route('/', methods=['GET']) 8 | def home(): 9 | dataset = {'page': 'Home', 'Message': 'successfully loaded the home page' , 'Timestamp': time.time()} 10 | jsondump = json.dumps(dataset) 11 | return jsondump 12 | 13 | @app.route('/user/', methods=['GET']) 14 | def request_shreya(): 15 | 16 | user_query = str(request.args.get('user')) 17 | 18 | dataset = {'page': 'request', 'Message': f'successfully loaded the request for {user_query} pages', 'Timestamp': time.time()} 19 | jsondump = json.dumps(dataset) 20 | 21 | return jsondump 22 | 23 | 24 | if __name__ == '__main__': 25 | app.run(port=2000) --------------------------------------------------------------------------------