{"activeVersionTag":"latest","latestAvailableVersionTag":"latest","collection":{"info":{"_postman_id":"bfa50d53-27c9-4be9-8009-121d6ce8e398","name":"Flask App APIs Documentation","description":"This document provides an overview and documentation of a Python script that creates a Flask web application connected to a MongoDB database. The application offers various API routes for managing student and student task data. Below is a detailed breakdown of the code, including explanations for each route.\n\n---\n\n## Requirements\n\n- Python 3\n- Flask\n- Flask-PyMongo\n- MongoDB\n    \n\n---\n\n## Setup\n\n1. Ensure that Python and the required dependencies are installed.\n2. Start a MongoDB server on `mongodb://localhost:27017` with a database named `school`.\n    \n\n---\n\n## Brief Code Explanation\n\n### Imports\n\n``` python\nfrom flask import Flask, jsonify, request\nfrom flask_pymongo import PyMongo\nfrom datetime import datetime\n\n ```\n\nThe script imports necessary libraries for creating a Flask application, interacting with a MongoDB database, and managing date values for the database.\n\n### Flask App Initialization\n\n``` python\napp = Flask(__name__)\napp.config['MONGO_URI'] = 'mongodb://localhost:27017/school'\nmongo = PyMongo(app)\n\n ```\n\nHere, a Flask app is created, and it is configured to use the specified MongoDB URI. A connection to the MongoDB database is established using Flask-PyMongo.\n\n### **`add_student`** Route - \\[ POST \\]\n\n``` python\n@app.route('/add_student', methods=['POST'])\ndef add_student():\n    # Extract data from the request\n    # ...\n    # Insert student data into the database\n    # ...\n    # Return a success response\n    # ...\n\n ```\n\nThis route allows the addition of a single student to the database. It extracts data from the JSON request and inserts it into the MongoDB `students` collection. The route returns a success response upon completion.\n\n### `add_students` Route - \\[ POST \\]\n\n``` python\n@app.route('/add_students', methods=['POST'])\ndef add_students():\n    # Extract data from the request\n    # ...\n    # Insert multiple students into the database\n    # ...\n    # Return a success response\n    # ...\n\n ```\n\nThis route is used for adding multiple students to the database in a single request. It expects a list of student objects in the request's JSON body and inserts them into the `students` collection.\n\n### `get_single_student` Route - \\[ GET \\]\n\n``` python\n@app.route(&#x27;/get_student/<student_id>&#x27;, methods=[&#x27;GET&#x27;])\ndef get_single_student(student_id):\n    # Find a single student by student_id\n    # ...\n    # Return the student as JSON\n    # ...\n\n ```\n\nThis route retrieves a single student's data by their `student_id` and returns it as a JSON response.\n\n### `get_all_students` Route - \\[ GET \\]\n\n``` python\n@app.route('/get_students', methods=['GET'])\ndef get_all_students():\n    # Find all students in the database\n    # ...\n    # Return a list of students as JSON\n    # ...\n\n ```\n\nThis route retrieves all student data from the database and returns it as a list of JSON objects.\n\n### `update_student` Route - \\[ PUT \\]\n\n``` python\n@app.route(&#x27;/update_student/<student_id>&#x27;, methods=[&#x27;PUT&#x27;])\ndef update_student(student_id):\n    # Extract data from the request\n    # ...\n    # Update the student's data in the database\n    # ...\n    # Return a success response\n    # ...\n\n ```\n\nThis route allows the update of a student's data by their `student_id`. It extracts the updated data from the request and updates the corresponding record in the database.\n\n### `soft_delete_student` Route -\\[ DELETE \\]\n\n``` python\n@app.route(&#x27;/soft_delete_student/<student_id>&#x27;, methods=[&#x27;DELETE&#x27;])\ndef soft_delete_student(student_id):\n    # Soft delete a student by setting 'is_deleted' to True\n    # ...\n    # Return a success response\n    # ...\n\n ```\n\nThis route soft deletes a student by setting their `is_deleted` field to True, indicating that they are marked for deletion.\n\n### `hard_delete_student` Route - DELETE\n\n``` python\n@app.route(&#x27;/hard_delete_student/<student_id>&#x27;, methods=[&#x27;DELETE&#x27;])\ndef hard_delete_student(student_id):\n    # Hard delete a student by removing the record from the database\n    # ...\n    # Return a success response\n    # ...\n\n ```\n\nThis route hard deletes a student by completely removing their record from the database.\n\n### Student Tasks Routes\n\nThe script also includes a set of API routes for managing student tasks. These routes have a similar structure to the student-related routes but are focused on tasks associated with students. They allow the addition, retrieval, update, and soft and hard deletion of student tasks.\n\n### Error Handling\n\n``` python\n@app.errorhandler(404)\ndef not_found(error=None):\n    # Handle 404 errors by returning a custom JSON response\n    # ...\n\n ```\n\nThe script defines an error handler for 404 errors, returning a custom JSON response indicating that the requested resource was not found.\n\n### Run the Application\n\n``` python\nif __name__ == '__main__':\n    app.run(debug=True)\n\n ```\n\nThis section starts the Flask application with debugging enabled if the script is executed directly.","schema":"https://schema.getpostman.com/json/collection/v2.0.0/collection.json","isPublicCollection":false,"owner":"30488427","team":5681102,"collectionId":"bfa50d53-27c9-4be9-8009-121d6ce8e398","publishedId":"2s9YR9YsmV","public":true,"publicUrl":"https://documenter-api.postman.tech/view/30488427/2s9YR9YsmV","privateUrl":"https://go.postman.co/documentation/30488427-bfa50d53-27c9-4be9-8009-121d6ce8e398","customColor":{"top-bar":"FFFFFF","right-sidebar":"303030","highlight":"FF6C37"},"documentationLayout":"classic-double-column","customisation":{"metaTags":[{"name":"description","value":"This is a simple Flask application in Python that is linked to a MongoDB database in order to create several APIs to perform different requests on the database"},{"name":"title","value":"Flask app APIs "}],"appearance":{"default":"dark","themes":[{"name":"dark","logo":null,"colors":{"top-bar":"212121","right-sidebar":"303030","highlight":"FF6C37"}},{"name":"light","logo":null,"colors":{"top-bar":"FFFFFF","right-sidebar":"303030","highlight":"FF6C37"}}]}},"version":"8.10.0","publishDate":"2023-10-19T04:57:45.000Z","activeVersionTag":"latest","documentationTheme":"light","metaTags":{"title":"Flask app APIs ","description":"This is a simple Flask application in Python that is linked to a MongoDB database in order to create several APIs to perform different requests on the database"},"logos":{"logoLight":null,"logoDark":null}},"statusCode":200},"environments":[],"user":{"authenticated":false,"permissions":{"publish":false}},"run":{"button":{"js":"https://run.pstmn.io/button.js","css":"https://run.pstmn.io/button.css"}},"web":"https://www.getpostman.com/","team":{"logo":"https://res.cloudinary.com/postman/image/upload/t_team_logo_pubdoc/v1/team/df95f61fa85218a303f109190150b3c63551b81a2bb1c79a453a83134de5e039","favicon":""},"isEnvFetchError":false,"languages":"[{\"key\":\"csharp\",\"label\":\"C#\",\"variant\":\"HttpClient\"},{\"key\":\"csharp\",\"label\":\"C#\",\"variant\":\"RestSharp\"},{\"key\":\"curl\",\"label\":\"cURL\",\"variant\":\"cURL\"},{\"key\":\"dart\",\"label\":\"Dart\",\"variant\":\"http\"},{\"key\":\"go\",\"label\":\"Go\",\"variant\":\"Native\"},{\"key\":\"http\",\"label\":\"HTTP\",\"variant\":\"HTTP\"},{\"key\":\"java\",\"label\":\"Java\",\"variant\":\"OkHttp\"},{\"key\":\"java\",\"label\":\"Java\",\"variant\":\"Unirest\"},{\"key\":\"javascript\",\"label\":\"JavaScript\",\"variant\":\"Fetch\"},{\"key\":\"javascript\",\"label\":\"JavaScript\",\"variant\":\"jQuery\"},{\"key\":\"javascript\",\"label\":\"JavaScript\",\"variant\":\"XHR\"},{\"key\":\"c\",\"label\":\"C\",\"variant\":\"libcurl\"},{\"key\":\"nodejs\",\"label\":\"NodeJs\",\"variant\":\"Axios\"},{\"key\":\"nodejs\",\"label\":\"NodeJs\",\"variant\":\"Native\"},{\"key\":\"nodejs\",\"label\":\"NodeJs\",\"variant\":\"Request\"},{\"key\":\"nodejs\",\"label\":\"NodeJs\",\"variant\":\"Unirest\"},{\"key\":\"objective-c\",\"label\":\"Objective-C\",\"variant\":\"NSURLSession\"},{\"key\":\"ocaml\",\"label\":\"OCaml\",\"variant\":\"Cohttp\"},{\"key\":\"php\",\"label\":\"PHP\",\"variant\":\"cURL\"},{\"key\":\"php\",\"label\":\"PHP\",\"variant\":\"Guzzle\"},{\"key\":\"php\",\"label\":\"PHP\",\"variant\":\"HTTP_Request2\"},{\"key\":\"php\",\"label\":\"PHP\",\"variant\":\"pecl_http\"},{\"key\":\"powershell\",\"label\":\"PowerShell\",\"variant\":\"RestMethod\"},{\"key\":\"python\",\"label\":\"Python\",\"variant\":\"http.client\"},{\"key\":\"python\",\"label\":\"Python\",\"variant\":\"Requests\"},{\"key\":\"r\",\"label\":\"R\",\"variant\":\"httr\"},{\"key\":\"r\",\"label\":\"R\",\"variant\":\"RCurl\"},{\"key\":\"ruby\",\"label\":\"Ruby\",\"variant\":\"Net::HTTP\"},{\"key\":\"shell\",\"label\":\"Shell\",\"variant\":\"Httpie\"},{\"key\":\"shell\",\"label\":\"Shell\",\"variant\":\"wget\"},{\"key\":\"swift\",\"label\":\"Swift\",\"variant\":\"URLSession\"}]","languageSettings":[{"key":"csharp","label":"C#","variant":"HttpClient"},{"key":"csharp","label":"C#","variant":"RestSharp"},{"key":"curl","label":"cURL","variant":"cURL"},{"key":"dart","label":"Dart","variant":"http"},{"key":"go","label":"Go","variant":"Native"},{"key":"http","label":"HTTP","variant":"HTTP"},{"key":"java","label":"Java","variant":"OkHttp"},{"key":"java","label":"Java","variant":"Unirest"},{"key":"javascript","label":"JavaScript","variant":"Fetch"},{"key":"javascript","label":"JavaScript","variant":"jQuery"},{"key":"javascript","label":"JavaScript","variant":"XHR"},{"key":"c","label":"C","variant":"libcurl"},{"key":"nodejs","label":"NodeJs","variant":"Axios"},{"key":"nodejs","label":"NodeJs","variant":"Native"},{"key":"nodejs","label":"NodeJs","variant":"Request"},{"key":"nodejs","label":"NodeJs","variant":"Unirest"},{"key":"objective-c","label":"Objective-C","variant":"NSURLSession"},{"key":"ocaml","label":"OCaml","variant":"Cohttp"},{"key":"php","label":"PHP","variant":"cURL"},{"key":"php","label":"PHP","variant":"Guzzle"},{"key":"php","label":"PHP","variant":"HTTP_Request2"},{"key":"php","label":"PHP","variant":"pecl_http"},{"key":"powershell","label":"PowerShell","variant":"RestMethod"},{"key":"python","label":"Python","variant":"http.client"},{"key":"python","label":"Python","variant":"Requests"},{"key":"r","label":"R","variant":"httr"},{"key":"r","label":"R","variant":"RCurl"},{"key":"ruby","label":"Ruby","variant":"Net::HTTP"},{"key":"shell","label":"Shell","variant":"Httpie"},{"key":"shell","label":"Shell","variant":"wget"},{"key":"swift","label":"Swift","variant":"URLSession"}],"languageOptions":[{"label":"C# - HttpClient","value":"csharp - HttpClient - C#"},{"label":"C# - RestSharp","value":"csharp - RestSharp - C#"},{"label":"cURL - cURL","value":"curl - cURL - cURL"},{"label":"Dart - http","value":"dart - http - Dart"},{"label":"Go - Native","value":"go - Native - Go"},{"label":"HTTP - HTTP","value":"http - HTTP - HTTP"},{"label":"Java - OkHttp","value":"java - OkHttp - Java"},{"label":"Java - Unirest","value":"java - Unirest - Java"},{"label":"JavaScript - Fetch","value":"javascript - Fetch - JavaScript"},{"label":"JavaScript - jQuery","value":"javascript - jQuery - JavaScript"},{"label":"JavaScript - XHR","value":"javascript - XHR - JavaScript"},{"label":"C - libcurl","value":"c - libcurl - C"},{"label":"NodeJs - Axios","value":"nodejs - Axios - NodeJs"},{"label":"NodeJs - Native","value":"nodejs - Native - NodeJs"},{"label":"NodeJs - Request","value":"nodejs - Request - NodeJs"},{"label":"NodeJs - Unirest","value":"nodejs - Unirest - NodeJs"},{"label":"Objective-C - NSURLSession","value":"objective-c - NSURLSession - Objective-C"},{"label":"OCaml - Cohttp","value":"ocaml - Cohttp - OCaml"},{"label":"PHP - cURL","value":"php - cURL - PHP"},{"label":"PHP - Guzzle","value":"php - Guzzle - PHP"},{"label":"PHP - HTTP_Request2","value":"php - HTTP_Request2 - PHP"},{"label":"PHP - pecl_http","value":"php - pecl_http - PHP"},{"label":"PowerShell - RestMethod","value":"powershell - RestMethod - PowerShell"},{"label":"Python - http.client","value":"python - http.client - Python"},{"label":"Python - Requests","value":"python - Requests - Python"},{"label":"R - httr","value":"r - httr - R"},{"label":"R - RCurl","value":"r - RCurl - R"},{"label":"Ruby - Net::HTTP","value":"ruby - Net::HTTP - Ruby"},{"label":"Shell - Httpie","value":"shell - Httpie - Shell"},{"label":"Shell - wget","value":"shell - wget - Shell"},{"label":"Swift - URLSession","value":"swift - URLSession - Swift"}],"layoutOptions":[{"value":"classic-single-column","label":"Single Column"},{"value":"classic-double-column","label":"Double Column"}],"versionOptions":[],"environmentOptions":[{"value":"0","label":"No Environment"}],"canonicalUrl":"https://documenter.gw.postman.com/view/metadata/2s9YR9YsmV"}