-
-
-[<< Day 25 ](../25_Day_Pandas/25_pandas.md) | [Day 27 >>](../27_Day_Python_with_mongodb/27_python_with_mongodb.md)
-
-![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
-
-- [📘 Day 26](#-day-26)
- - [Python for Web](#python-for-web)
- - [Flask](#flask)
- - [Folder structure](#folder-structure)
- - [Setting up your project directory](#setting-up-your-project-directory)
- - [Creating routes](#creating-routes)
- - [Creating templates](#creating-templates)
- - [Python Script](#python-script)
- - [Navigation](#navigation)
- - [Creating a layout](#creating-a-layout)
- - [Serving Static File](#serving-static-file)
- - [Deployment](#deployment)
- - [Creating Heroku account](#creating-heroku-account)
- - [Login to Heroku](#login-to-heroku)
- - [Create requirements and Procfile](#create-requirements-and-procfile)
- - [Pushing project to heroku](#pushing-project-to-heroku)
- - [Exercises: Day 26](#exercises-day-26)
-
-# 📘 Day 26
-
-## Python for Web
-
-Python is a general purpose programming language and it can be used for many places. In this section, we will see how we use Python for the web. There are many Python web frame works. Django and Flask are the most popular ones. Today, we will see how to use Flask for web development.
-
-### Flask
-
-Flask is a web development framework written in Python. Flask uses Jinja2 template engine. Flask can be also used with other modern front libraries such as React.
-
-If you did not install the virtualenv package yet install it first. Virtual environment will allows to isolate project dependencies from the local machine dependencies.
-
-#### Folder structure
-
-After completing all the step, your project file structure should look like this:
-
-```sh
-
-├── Procfile
-├── app.py
-├── env
-│ ├── bin
-├── requirements.txt
-├── static
-│ └── css
-│ └── main.css
-└── templates
- ├── about.html
- ├── home.html
- ├── layout.html
- ├── post.html
- └── result.html
-```
-
-### Setting up your project directory
-
-Follow the following steps to get started with Flask.
-
-Step 1: install virtualenv using the following command.
-
-```sh
-pip install virtualenv
-```
-
-Step 2:
-
-```sh
-asabeneh@Asabeneh:~/Desktop$ mkdir python_for_web
-asabeneh@Asabeneh:~/Desktop$ cd python_for_web/
-asabeneh@Asabeneh:~/Desktop/python_for_web$ virtualenv venv
-asabeneh@Asabeneh:~/Desktop/python_for_web$ source venv/bin/activate
-(env) asabeneh@Asabeneh:~/Desktop/python_for_web$ pip freeze
-(env) asabeneh@Asabeneh:~/Desktop/python_for_web$ pip install Flask
-(env) asabeneh@Asabeneh:~/Desktop/python_for_web$ pip freeze
-Click==7.0
-Flask==1.1.1
-itsdangerous==1.1.0
-Jinja2==2.10.3
-MarkupSafe==1.1.1
-Werkzeug==0.16.0
-(env) asabeneh@Asabeneh:~/Desktop/python_for_web$
-```
-
-We created a project director named python_for_web. Inside the project we created a virtual environment *venv* which could be any name but I prefer to call it _venv_. Then we activated the virtual environment. We used pip freeze to check the installed packages in the project directory. The result of pip freeze was empty because a package was not installed yet.
-
-Now, let's create app.py file in the project directory and write the following code. The app.py file will be the main file in the project. The following code has flask module, os module.
-
-### Creating routes
-
-The home route.
-
-```py
-# let's import the flask
-from flask import Flask
-import os # importing operating system module
-
-app = Flask(__name__)
-
-@app.route('/') # this decorator create the home route
-def home ():
- return '
'
-
-
-if __name__ == '__main__':
- # for deployment we use the environ
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-To run the flask application, write python app.py in the main flask application directory.
-
-After you run _python app.py_ check local host 5000.
-
-Let us add additional route.
-Creating about route
-
-```py
-# let's import the flask
-from flask import Flask
-import os # importing operating system module
-
-app = Flask(__name__)
-
-@app.route('/') # this decorator create the home route
-def home ():
- return '
'
-
-if __name__ == '__main__':
- # for deployment we use the environ
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-Now, we added the about route in the above code. How about if we want to render an HTML file instead of string? It is possible to render HTML file using the function *render_templae*. Let us create a folder called templates and create home.html and about.html in the project directory. Let us also import the *render_template* function from flask.
-
-### Creating templates
-
-Create the HTML files inside templates folder.
-
-home.html
-
-```html
-
-
-
-
-
- Home
-
-
-
-
-
-
-```
-
-### Python Script
-
-app.py
-
-```py
-# let's import the flask
-from flask import Flask, render_template
-import os # importing operating system module
-
-app = Flask(__name__)
-
-@app.route('/') # this decorator create the home route
-def home ():
- return render_template('home.html')
-
-@app.route('/about')
-def about():
- return render_template('about.html')
-
-if __name__ == '__main__':
- # for deployment we use the environ
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-As you can see to go to different pages or to navigate we need a navigation. Let's add a link to each page or let's create a layout which we use to every page.
-
-### Navigation
-
-```html
-
-```
-
-Now, we can navigate between the pages using the above link. Let us create additional page which handle form data. You can call it any name, I like to call it post.html.
-
-We can inject data to the HTML files using Jinja2 template engine.
-
-```py
-# let's import the flask
-from flask import Flask, render_template, request, redirect, url_for
-import os # importing operating system module
-
-app = Flask(__name__)
-
-@app.route('/') # this decorator create the home route
-def home ():
- techs = ['HTML', 'CSS', 'Flask', 'Python']
- name = '30 Days Of Python Programming'
- return render_template('home.html', techs=techs, name = name, title = 'Home')
-
-@app.route('/about')
-def about():
- name = '30 Days Of Python Programming'
- return render_template('about.html', name = name, title = 'About Us')
-
-@app.route('/post')
-def post():
- name = 'Text Analyzer'
- return render_template('post.html', name = name, title = name)
-
-
-if __name__ == '__main__':
- # for deployment
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-Let's see the templates too:
-
-home.html
-
-```html
-
-
-
-
-
- Home
-
-
-
-
-
-
-```
-
-### Creating a layout
-
-In the template files, there are lots of repeated codes, we can write a layout and we can remove the repetition. Let's create layout.html inside the templates folder.
-After we create the layout we will import to every file.
-
-#### Serving Static File
-
-Create a static folder in your project directory. Inside the static folder create CSS or styles folder and create a CSS stylesheet. We use the *url_for* module to serve the static file.
-
-layout.html
-
-```html
-
-
-
-
-
-
-
- {% if title %}
- 30 Days of Python - {{ title}}
- {% else %}
- 30 Days of Python
- {% endif %}
-
-
-
-
-
-
-
- {% block content %} {% endblock %}
-
-
-
-```
-
-Now, lets remove all the repeated code in the other template files and import the layout.html. The href is using _url_for_ function with the name of the route function to connect each navigation route.
-
-home.html
-
-```html
-{% extends 'layout.html' %} {% block content %}
-
-
Welcome to {{name}}
-
- This application clean texts and analyse the number of word, characters and
- most frequent words in the text. Check it out by click text analyzer at the
- menu. You need the following technologies to build this web application:
-
-
-{% endblock %}
-```
-
-Request methods, there are different request methods(GET, POST, PUT, DELETE) are the common request methods which allow us to do CRUD(Create, Read, Update, Delete) operation.
-
-In the post, route we will use GET and POST method alternative depending on the type of request, check how it looks in the code below. The request method is a function to handle request methods and also to access form data.
-app.py
-
-```py
-# let's import the flask
-from flask import Flask, render_template, request, redirect, url_for
-import os # importing operating system module
-
-app = Flask(__name__)
-# to stop caching static file
-app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
-
-
-
-@app.route('/') # this decorator create the home route
-def home ():
- techs = ['HTML', 'CSS', 'Flask', 'Python']
- name = '30 Days Of Python Programming'
- return render_template('home.html', techs=techs, name = name, title = 'Home')
-
-@app.route('/about')
-def about():
- name = '30 Days Of Python Programming'
- return render_template('about.html', name = name, title = 'About Us')
-
-@app.route('/result')
-def result():
- return render_template('result.html')
-
-@app.route('/post', methods= ['GET','POST'])
-def post():
- name = 'Text Analyzer'
- if request.method == 'GET':
- return render_template('post.html', name = name, title = name)
- if request.method =='POST':
- content = request.form['content']
- print(content)
- return redirect(url_for('result'))
-
-if __name__ == '__main__':
- # for deployment
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-So far, we have seen how to use template and how to inject data to template, how to a common layout.
-Now, lets handle static file. Create a folder called static in the project director and create a folder called css. Inside css folder create main.css. Your main. css file will be linked to the layout.html.
-
-You don't have to write the css file, copy and use it. Let's move on to deployment.
-
-### Deployment
-
-#### Creating Heroku account
-
-Heroku provides a free deployment service for both front end and fullstack applications. Create an account on [heroku](https://www.heroku.com/) and install the heroku [CLI](https://devcenter.heroku.com/articles/heroku-cli) for you machine.
-After installing heroku write the following command
-
-#### Login to Heroku
-
-```sh
-asabeneh@Asabeneh:~$ heroku login
-heroku: Press any key to open up the browser to login or q to exit:
-```
-
-Let's see the result by clicking any key from the keyboard. When you press any key from you keyboard it will open the heroku login page and click the login page. Then you will local machine will be connected to the remote heroku server. If you are connected to remote server, you will see this.
-
-```sh
-asabeneh@Asabeneh:~$ heroku login
-heroku: Press any key to open up the browser to login or q to exit:
-Opening browser to https://cli-auth.heroku.com/auth/browser/be12987c-583a-4458-a2c2-ba2ce7f41610
-Logging in... done
-Logged in as asabeneh@gmail.com
-asabeneh@Asabeneh:~$
-```
-
-#### Create requirements and Procfile
-
-Before we push our code to remote server, we need requirements
-
-- requirements.txt
-- Procfile
-
-```sh
-(env) asabeneh@Asabeneh:~/Desktop/python_for_web$ pip freeze
-Click==7.0
-Flask==1.1.1
-itsdangerous==1.1.0
-Jinja2==2.10.3
-MarkupSafe==1.1.1
-Werkzeug==0.16.0
-(env) asabeneh@Asabeneh:~/Desktop/python_for_web$ touch requirements.txt
-(env) asabeneh@Asabeneh:~/Desktop/python_for_web$ pip freeze > requirements.txt
-(env) asabeneh@Asabeneh:~/Desktop/python_for_web$ cat requirements.txt
-Click==7.0
-Flask==1.1.1
-itsdangerous==1.1.0
-Jinja2==2.10.3
-MarkupSafe==1.1.1
-Werkzeug==0.16.0
-(env) asabeneh@Asabeneh:~/Desktop/python_for_web$ touch Procfile
-(env) asabeneh@Asabeneh:~/Desktop/python_for_web$ ls
-Procfile env/ static/
-app.py requirements.txt templates/
-(env) asabeneh@Asabeneh:~/Desktop/python_for_web$
-```
-
-The Procfile will have the command which run the application in the web server in our case on Heroku.
-
-```sh
-web: python app.py
-```
-
-#### Pushing project to heroku
-
-Now, it is ready to be deployed. Steps to deploy the application on heroku
-
-1. git init
-2. git add .
-3. git commit -m "commit message"
-4. heroku create 'name of the app as one word'
-5. git push heroku master
-6. heroku open(to launch the deployed application)
-
-After this step you will get an application like [this](http://thirdaysofpython-practice.herokuapp.com/)
-
-## Exercises: Day 26
-
-1. You will build [this application](https://thirtydaysofpython-v1-final.herokuapp.com/). Only the text analyser part is left
-
-
-🎉 CONGRATULATIONS ! 🎉
-
-[<< Day 25 ](../25_Day_Pandas/25_pandas.md) | [Day 27 >>](../27_Day_Python_with_mongodb/27_python_with_mongodb.md)
\ No newline at end of file
diff --git a/docs/27_FastAPI.md b/docs/27_FastAPI.md
new file mode 100644
index 0000000..810cb15
--- /dev/null
+++ b/docs/27_FastAPI.md
@@ -0,0 +1 @@
+[FastAPI (tiangolo.com)](https://fastapi.tiangolo.com/)
\ No newline at end of file
diff --git a/docs/27_python_with_mongodb.md b/docs/27_python_with_mongodb.md
deleted file mode 100644
index b708ed9..0000000
--- a/docs/27_python_with_mongodb.md
+++ /dev/null
@@ -1,659 +0,0 @@
-
-
-[<< Day 26](../26_Day_Python_web/26_python_web.md) | [Day 28 >>](../28_Day_API/28_API.md)
-
-![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
-
-- [📘 Day 27](#-day-27)
-- [Python with MongoDB](#python-with-mongodb)
- - [MongoDB](#mongodb)
- - [SQL versus NoSQL](#sql-versus-nosql)
- - [Getting Connection String(MongoDB URI)](#getting-connection-stringmongodb-uri)
- - [Connecting Flask application to MongoDB Cluster](#connecting-flask-application-to-mongodb-cluster)
- - [Creating a database and collection](#creating-a-database-and-collection)
- - [Inserting many documents to collection](#inserting-many-documents-to-collection)
- - [MongoDB Find](#mongodb-find)
- - [Find with Query](#find-with-query)
- - [Find query with modifier](#find-query-with-modifier)
- - [Limiting documents](#limiting-documents)
- - [Find with sort](#find-with-sort)
- - [Update with query](#update-with-query)
- - [Delete Document](#delete-document)
- - [Drop a collection](#drop-a-collection)
- - [💻 Exercises: Day 27](#-exercises-day-27)
-
-# 📘 Day 27
-
-# Python with MongoDB
-
-Python is a backend technology and it can be connected with different data base applications. It can be connected to both SQL and noSQL databases. In this section, we connect Python with MongoDB database which is noSQL database.
-
-## MongoDB
-
-MongoDB is a NoSQL database. MongoDB stores data in a JSON like document which make MongoDB very flexible and scalable. Let us see the different terminologies of SQL and NoSQL databases. The following table will make the difference between SQL versus NoSQL databases.
-
-### SQL versus NoSQL
-
-![SQL versus NoSQL](../images/mongoDB/sql-vs-nosql.png)
-
-In this section, we will focus on a NoSQL database MongoDB. Lets sign up on [mongoDB](https://www.mongodb.com/) by click on the sign in button then click register on the next page.
-
-![MongoDB Sign up pages](../images/mongoDB/mongodb-signup-page.png)
-
-Complete the fields and click continue
-
-![Mongodb register](../images/mongoDB/mongodb-register.png)
-
-Select the free plan
-
-![Mongodb free plan](../images/mongoDB/mongodb-free.png)
-
-Choose the proximate free region and give any name for you cluster.
-
-![Mongodb cluster name](../images/mongoDB/mongodb-cluster-name.png)
-
-Now, a free sandbox is created
-
-![Mongodb sandbox](../images/mongoDB/mongodb-sandbox.png)
-
-All local host access
-
-![Mongodb allow ip access](../images/mongoDB/mongodb-allow-ip-access.png)
-
-Add user and password
-
-![Mongodb add user](../images/mongoDB/mongodb-add-user.png)
-
-Create a mongoDB uri link
-
-![Mongodb create uri](../images/mongoDB/mongodb-create-uri.png)
-
-Select Python 3.6 or above driver
-
-![Mongodb python driver](../images/mongoDB/mongodb-python-driver.png)
-
-### Getting Connection String(MongoDB URI)
-
-Copy the connection string link and you will get something like this
-
-```sh
-mongodb+srv://asabeneh:@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority
-```
-
-Do not worry about the url, it is a means to connect your application with mongoDB.
-Let us replace the password placeholder with the password you used to add a user.
-
-**Example:**
-
-```sh
-mongodb+srv://asabeneh:123123123@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority
-```
-
-Now, I replaced everything and the password is 123123 and the name of the database is thirty_days_python. This is just an example, your password must be a bit stronger than this.
-
-Python needs a mongoDB driver to access mongoDB database. We will use _pymongo_ with _dnspython_ to connect our application with mongoDB base . Inside your project directory install pymongo and dnspython.
-
-```sh
-pip install pymongo dnspython
-```
-
-The "dnspython" module must be installed to use mongodb+srv:// URIs. The dnspython is a DNS toolkit for Python. It supports almost all record types.
-
-### Connecting Flask application to MongoDB Cluster
-
-```py
-# let's import the flask
-from flask import Flask, render_template
-import os # importing operating system module
-MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-print(client.list_database_names())
-
-app = Flask(__name__)
-if __name__ == '__main__':
- # for deployment we use the environ
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-
-```
-
-When we run the above code we get the default mongoDB databases.
-
-```sh
-['admin', 'local']
-```
-
-### Creating a database and collection
-
-Let us create a database, database and collection in mongoDB will be created if it doesn't exist. Let's create a data base name _thirty_days_of_python_ and _students_ collection.
-To create a database
-
-```sh
-db = client.name_of_databse # we can create a database like this or the second way
-db = client['name_of_database']
-```
-
-```py
-# let's import the flask
-from flask import Flask, render_template
-import os # importing operating system module
-MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-# Creating database
-db = client.thirty_days_of_python
-# Creating students collection and inserting a document
-db.students.insert_one({'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 250})
-print(client.list_database_names())
-
-app = Flask(__name__)
-if __name__ == '__main__':
- # for deployment we use the environ
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-After we create a database, we also created a students collection and we used *insert_one()* method to insert a document.
-Now, the database *thirty_days_of_python* and *students* collection have been created and the document has been inserted.
-Check your mongoDB cluster and you will see both the database and the collection. Inside the collection, there will be a document.
-
-```sh
-['thirty_days_of_python', 'admin', 'local']
-```
-
-If you see this on the mongoDB cluster, it means you have successfully created a database and a collection.
-
-![Creating database and collection](../images/mongoDB/mongodb-creating_database.png)
-
-If you have seen on the figure, the document has been created with a long id which acts as a primary key. Every time we create a document mongoDB create and unique id for it.
-
-### Inserting many documents to collection
-
-The *insert_one()* method inserts one item at a time if we want to insert many documents at once either we use *insert_many()* method or for loop.
-We can use for loop to inset many documents at once.
-
-```py
-# let's import the flask
-from flask import Flask, render_template
-import os # importing operating system module
-MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-
-students = [
- {'name':'David','country':'UK','city':'London','age':34},
- {'name':'John','country':'Sweden','city':'Stockholm','age':28},
- {'name':'Sami','country':'Finland','city':'Helsinki','age':25},
- ]
-for student in students:
- db.students.insert_one(student)
-
-
-app = Flask(__name__)
-if __name__ == '__main__':
- # for deployment we use the environ
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-### MongoDB Find
-
-The *find()* and *findOne()* methods are common method to find data in a collection in mongoDB database. It is similar to the SELECT statement in a MySQL database.
-Let us use the _find_one()_ method to get a document in a database collection.
-
-- \*find_one({"\_id": ObjectId("id"}): Gets the first occurrence if an id is not provided
-
-```py
-# let's import the flask
-from flask import Flask, render_template
-import os # importing operating system module
-MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-student = db.students.find_one()
-print(student)
-
-
-app = Flask(__name__)
-if __name__ == '__main__':
- # for deployment we use the environ
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-
-```
-
-```sh
-{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Helsinki', 'city': 'Helsinki', 'age': 250}
-```
-
-The above query returns the first entry but we can target specific document using specific \_id. Let us do one example, use David's id to get David object.
-'\_id':ObjectId('5df68a23f106fe2d315bbc8c')
-
-```py
-# let's import the flask
-from flask import Flask, render_template
-import os # importing operating system module
-from bson.objectid import ObjectId # id object
-MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-student = db.students.find_one({'_id':ObjectId('5df68a23f106fe2d315bbc8c')})
-print(student)
-
-app = Flask(__name__)
-if __name__ == '__main__':
- # for deployment we use the environ
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-```sh
-{'_id': ObjectId('5df68a23f106fe2d315bbc8c'), 'name': 'David', 'country': 'UK', 'city': 'London', 'age': 34}
-```
-
-We have seen, how to use _find_one()_ using the above examples. Let's move one to _find()_
-
-- _find()_: returns all the occurrence from a collection if we don't pass a query object. The object is pymongo.cursor object.
-
-```py
-# let's import the flask
-from flask import Flask, render_template
-import os # importing operating system module
-
-MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-students = db.students.find()
-for student in students:
- print(student)
-
-app = Flask(__name__)
-if __name__ == '__main__':
- # for deployment we use the environ
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-```sh
-{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 250}
-{'_id': ObjectId('5df68a23f106fe2d315bbc8c'), 'name': 'David', 'country': 'UK', 'city': 'London', 'age': 34}
-{'_id': ObjectId('5df68a23f106fe2d315bbc8d'), 'name': 'John', 'country': 'Sweden', 'city': 'Stockholm', 'age': 28}
-{'_id': ObjectId('5df68a23f106fe2d315bbc8e'), 'name': 'Sami', 'country': 'Finland', 'city': 'Helsinki', 'age': 25}
-```
-
-We can specify which fields to return by passing second object in the _find({}, {})_. 0 means not include and 1 means include but we can not mix 0 and 1, except for \_id.
-
-```py
-# let's import the flask
-from flask import Flask, render_template
-import os # importing operating system module
-
-MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-students = db.students.find({}, {"_id":0, "name": 1, "country":1}) # 0 means not include and 1 means include
-for student in students:
- print(student)
-
-app = Flask(__name__)
-if __name__ == '__main__':
- # for deployment we use the environ
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-```sh
-{'name': 'Asabeneh', 'country': 'Finland'}
-{'name': 'David', 'country': 'UK'}
-{'name': 'John', 'country': 'Sweden'}
-{'name': 'Sami', 'country': 'Finland'}
-```
-
-### Find with Query
-
-In mongoDB find take a query object. We can pass a query object and we can filter the documents we like to filter out.
-
-```py
-# let's import the flask
-from flask import Flask, render_template
-import os # importing operating system module
-
-MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-
-query = {
- "country":"Finland"
-}
-students = db.students.find(query)
-
-for student in students:
- print(student)
-
-
-app = Flask(__name__)
-if __name__ == '__main__':
- # for deployment we use the environ
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-```sh
-{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 250}
-{'_id': ObjectId('5df68a23f106fe2d315bbc8e'), 'name': 'Sami', 'country': 'Finland', 'city': 'Helsinki', 'age': 25}
-```
-
-Query with modifiers
-
-```py
-# let's import the flask
-from flask import Flask, render_template
-import os # importing operating system module
-import pymongo
-
-MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-
-query = {
- "city":"Helsinki"
-}
-students = db.students.find(query)
-for student in students:
- print(student)
-
-
-app = Flask(__name__)
-if __name__ == '__main__':
- # for deployment we use the environ
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-```sh
-{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 250}
-{'_id': ObjectId('5df68a23f106fe2d315bbc8e'), 'name': 'Sami', 'country': 'Finland', 'city': 'Helsinki', 'age': 25}
-```
-
-### Find query with modifier
-
-```py
-# let's import the flask
-from flask import Flask, render_template
-import os # importing operating system module
-import pymongo
-
-MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-query = {
- "country":"Finland",
- "city":"Helsinki"
-}
-students = db.students.find(query)
-for student in students:
- print(student)
-
-
-app = Flask(__name__)
-if __name__ == '__main__':
- # for deployment we use the environ
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-```sh
-{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 250}
-{'_id': ObjectId('5df68a23f106fe2d315bbc8e'), 'name': 'Sami', 'country': 'Finland', 'city': 'Helsinki', 'age': 25}
-```
-
-Query with modifiers
-
-```py
-# let's import the flask
-from flask import Flask, render_template
-import os # importing operating system module
-import pymongo
-
-MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-query = {"age":{"$gt":30}}
-students = db.students.find(query)
-for student in students:
- print(student)
-
-app = Flask(__name__)
-if __name__ == '__main__':
- # for deployment we use the environ
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-```sh
-{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 250}
-{'_id': ObjectId('5df68a23f106fe2d315bbc8c'), 'name': 'David', 'country': 'UK', 'city': 'London', 'age': 34}
-```
-
-```py
-# let's import the flask
-from flask import Flask, render_template
-import os # importing operating system module
-import pymongo
-
-MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-query = {"age":{"$gt":30}}
-students = db.students.find(query)
-for student in students:
- print(student)
-```
-
-```sh
-{'_id': ObjectId('5df68a23f106fe2d315bbc8d'), 'name': 'John', 'country': 'Sweden', 'city': 'Stockholm', 'age': 28}
-{'_id': ObjectId('5df68a23f106fe2d315bbc8e'), 'name': 'Sami', 'country': 'Finland', 'city': 'Helsinki', 'age': 25}
-```
-
-### Limiting documents
-
-We can limit the number of documents we return using the _limit()_ method.
-
-```py
-# let's import the flask
-from flask import Flask, render_template
-import os # importing operating system module
-import pymongo
-
-MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-db.students.find().limit(3)
-```
-
-### Find with sort
-
-By default, sort is in ascending order. We can change the sorting to descending order by adding -1 parameter.
-
-```py
-# let's import the flask
-from flask import Flask, render_template
-import os # importing operating system module
-import pymongo
-
-MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-students = db.students.find().sort('name')
-for student in students:
- print(student)
-
-
-students = db.students.find().sort('name',-1)
-for student in students:
- print(student)
-
-students = db.students.find().sort('age')
-for student in students:
- print(student)
-
-students = db.students.find().sort('age',-1)
-for student in students:
- print(student)
-
-app = Flask(__name__)
-if __name__ == '__main__':
- # for deployment we use the environ
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-Ascending order
-
-```sh
-{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 250}
-{'_id': ObjectId('5df68a23f106fe2d315bbc8c'), 'name': 'David', 'country': 'UK', 'city': 'London', 'age': 34}
-{'_id': ObjectId('5df68a23f106fe2d315bbc8d'), 'name': 'John', 'country': 'Sweden', 'city': 'Stockholm', 'age': 28}
-{'_id': ObjectId('5df68a23f106fe2d315bbc8e'), 'name': 'Sami', 'country': 'Finland', 'city': 'Helsinki', 'age': 25}
-```
-
-Descending order
-
-```sh
-{'_id': ObjectId('5df68a23f106fe2d315bbc8e'), 'name': 'Sami', 'country': 'Finland', 'city': 'Helsinki', 'age': 25}
-{'_id': ObjectId('5df68a23f106fe2d315bbc8d'), 'name': 'John', 'country': 'Sweden', 'city': 'Stockholm', 'age': 28}
-{'_id': ObjectId('5df68a23f106fe2d315bbc8c'), 'name': 'David', 'country': 'UK', 'city': 'London', 'age': 34}
-{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 250}
-```
-
-### Update with query
-
-We will use *update_one()* method to update one item. It takes two object one is a query and the second is the new object.
-The first person, Asabeneh got a very implausible age. Let us update Asabeneh's age.
-
-```py
-# let's import the flask
-from flask import Flask, render_template
-import os # importing operating system module
-import pymongo
-
-MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-
-query = {'age':250}
-new_value = {'$set':{'age':38}}
-
-db.students.update_one(query, new_value)
-# lets check the result if the age is modified
-for student in db.students.find():
- print(student)
-
-
-app = Flask(__name__)
-if __name__ == '__main__':
- # for deployment we use the environ
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-```sh
-{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 38}
-{'_id': ObjectId('5df68a23f106fe2d315bbc8c'), 'name': 'David', 'country': 'UK', 'city': 'London', 'age': 34}
-{'_id': ObjectId('5df68a23f106fe2d315bbc8d'), 'name': 'John', 'country': 'Sweden', 'city': 'Stockholm', 'age': 28}
-{'_id': ObjectId('5df68a23f106fe2d315bbc8e'), 'name': 'Sami', 'country': 'Finland', 'city': 'Helsinki', 'age': 25}
-```
-
-When we want to update many documents at once we use *upate_many()* method.
-
-### Delete Document
-
-The method *delete_one()* deletes one document. The *delete_one()* takes a query object parameter. It only removes the first occurrence.
-Let us remove one John from the collection.
-
-```py
-# let's import the flask
-from flask import Flask, render_template
-import os # importing operating system module
-import pymongo
-
-MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-
-query = {'name':'John'}
-db.students.delete_one(query)
-
-for student in db.students.find():
- print(student)
-# lets check the result if the age is modified
-for student in db.students.find():
- print(student)
-
-
-app = Flask(__name__)
-if __name__ == '__main__':
- # for deployment we use the environ
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-```sh
-{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 38}
-{'_id': ObjectId('5df68a23f106fe2d315bbc8c'), 'name': 'David', 'country': 'UK', 'city': 'London', 'age': 34}
-{'_id': ObjectId('5df68a23f106fe2d315bbc8e'), 'name': 'Sami', 'country': 'Finland', 'city': 'Helsinki', 'age': 25}
-```
-
-As you can see John has been removed from the collection.
-
-When we want to delete many documents we use *delete_many()* method, it takes a query object. If we pass an empty query object to *delete_many({})* it will delete all the documents in the collection.
-
-### Drop a collection
-
-Using the _drop()_ method we can delete a collection from a database.
-
-```py
-# let's import the flask
-from flask import Flask, render_template
-import os # importing operating system module
-import pymongo
-
-MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-db.students.drop()
-```
-
-Now, we have deleted the students collection from the database.
-
-## 💻 Exercises: Day 27
-
-🎉 CONGRATULATIONS ! 🎉
-
-[<< Day 26](../26_Day_Python_web/26_python_web.md) | [Day 28 >>](../28_Day_API/28_API.md)
diff --git a/docs/28_API.md b/docs/28_API.md
deleted file mode 100644
index 18532bc..0000000
--- a/docs/28_API.md
+++ /dev/null
@@ -1,162 +0,0 @@
-
-
-
-[<< Day 27](../27_Day_Python_with_mongodb/27_python_with_mongodb.md) | [Day 29 >>](../29_Day_Building_API/29_building_API.md)
-
-![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
-
-- [📘 Day 28](#-day-28)
-- [Application Programming Interface(API)](#application-programming-interfaceapi)
- - [API](#api)
- - [Building API](#building-api)
- - [HTTP(Hypertext Transfer Protocol)](#httphypertext-transfer-protocol)
- - [Structure of HTTP](#structure-of-http)
- - [Initial Request Line(Status Line)](#initial-request-linestatus-line)
- - [Initial Response Line(Status Line)](#initial-response-linestatus-line)
- - [Header Fields](#header-fields)
- - [The message body](#the-message-body)
- - [Request Methods](#request-methods)
- - [💻 Exercises: Day 28](#-exercises-day-28)
-
-# 📘 Day 28
-
-# Application Programming Interface(API)
-
-## API
-
-API stands for Application Programming Interface. The kind of API we will cover in this section is going to be Web APIs.
-Web APIs are the defined interfaces through which interactions happen between an enterprise and applications that use its assets, which also is a Service Level Agreement (SLA) to specify the functional provider and expose the service path or URL for its API users.
-
-In the context of web development, an API is defined as a set of specifications, such as Hypertext Transfer Protocol (HTTP) request messages, along with a definition of the structure of response messages, usually in an XML or a JavaScript Object Notation (JSON) format.
-
-Web API has been moving away from Simple Object Access Protocol (SOAP) based web services and service-oriented architecture (SOA) towards more direct representational state transfer (REST) style web resources.
-
-Social media services, web APIs have allowed web communities to share content and data between communities and different platforms.
-
-Using API, content that is created in one place dynamically can be posted and updated to multiple locations on the web.
-
-For example, Twitter's REST API allows developers to access core Twitter data and the Search API provides methods for developers to interact with Twitter Search and trends data.
-
-Many applications provide API end points. Some examples of API such as the countries [API](https://restcountries.eu/rest/v2/all), [cat's breed API](https://api.thecatapi.com/v1/breeds).
-
-In this section, we will cover a RESTful API that uses HTTP request methods to GET, PUT, POST and DELETE data.
-
-## Building API
-
-RESTful API is an application program interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data. In the previous sections, we have learned about python, flask and mongoDB. We will use the knowledge we acquire to develop a RESTful API using Python flask and mongoDB database. Every application which has CRUD(Create, Read, Update, Delete) operation has an API to create data, to get data, to update data or to delete data from a database.
-
-To build an API, it is good to understand HTTP protocol and HTTP request and response cycle.
-
-## HTTP(Hypertext Transfer Protocol)
-
-HTTP is an established communication protocol between a client and a server. A client in this case is a browser and server is the place where you access data. HTTP is a network protocol used to deliver resources which could be files on the World Wide Web, whether they are HTML files, image files, query results, scripts, or other file types.
-
-A browser is an HTTP client because it sends requests to an HTTP server (Web server), which then sends responses back to the client.
-
-## Structure of HTTP
-
-HTTP uses client-server model. An HTTP client opens a connection and sends a request message to an HTTP server and the HTTP server returns response message which is the requested resources. When the request response cycle completes the server closes the connection.
-
-![HTTP request response cycle](../images/http_request_response_cycle.png)
-
-The format of the request and response messages are similar. Both kinds of messages have
-
-- an initial line,
-- zero or more header lines,
-- a blank line (i.e. a CRLF by itself), and
-- an optional message body (e.g. a file, or query data, or query output).
-
-Let us an example of request and response messages by navigating this site:https://thirtydaysofpython-v1-final.herokuapp.com/. This site has been deployed on Heroku free dyno and in some months may not work because of high request. Support this work to make the server run all the time.
-
-![Request and Response header](../images/request_response_header.png)
-
-## Initial Request Line(Status Line)
-
-The initial request line is different from the response.
-A request line has three parts, separated by spaces:
-
-- method name(GET, POST, HEAD)
-- path of the requested resource,
-- the version of HTTP being used. eg GET / HTTP/1.1
-
-GET is the most common HTTP that helps to get or read resource and POST is a common request method to create resource.
-
-### Initial Response Line(Status Line)
-
-The initial response line, called the status line, also has three parts separated by spaces:
-
-- HTTP version
-- Response status code that gives the result of the request, and a reason which describes the status code. Example of status lines are:
- HTTP/1.0 200 OK
- or
- HTTP/1.0 404 Not Found
- Notes:
-
-The most common status codes are:
-200 OK: The request succeeded, and the resulting resource (e.g. file or script output) is returned in the message body.
-500 Server Error
-A complete list of HTTP status code can be found [here](https://httpstatuses.com/). It can be also found [here](https://httpstatusdogs.com/).
-
-### Header Fields
-
-As you have seen in the above screenshot, header lines provide information about the request or response, or about the object sent in the message body.
-
-```sh
-GET / HTTP/1.1
-Host: thirtydaysofpython-v1-final.herokuapp.com
-Connection: keep-alive
-Pragma: no-cache
-Cache-Control: no-cache
-Upgrade-Insecure-Requests: 1
-User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36
-Sec-Fetch-User: ?1
-Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
-Sec-Fetch-Site: same-origin
-Sec-Fetch-Mode: navigate
-Referer: https://thirtydaysofpython-v1-final.herokuapp.com/post
-Accept-Encoding: gzip, deflate, br
-Accept-Language: en-GB,en;q=0.9,fi-FI;q=0.8,fi;q=0.7,en-CA;q=0.6,en-US;q=0.5,fr;q=0.4
-```
-
-### The message body
-
-An HTTP message may have a body of data sent after the header lines. In a response, this is where the requested resource is returned to the client (the most common use of the message body), or perhaps explanatory text if there's an error. In a request, this is where user-entered data or uploaded files are sent to the server.
-
-If an HTTP message includes a body, there are usually header lines in the message that describe the body. In particular,
-
-The Content-Type: header gives the MIME-type of the data in the body(text/html, application/json, text/plain, text/css, image/gif).
-The Content-Length: header gives the number of bytes in the body.
-
-### Request Methods
-
-The GET, POST, PUT and DELETE are the HTTP request methods which we are going to implement an API or a CRUD operation application.
-
-1. GET: GET method is used to retrieve and get information from the given server using a given URI. Requests using GET should only retrieve data and should have no other effect on the data.
-
-2. POST: POST request is used to create data and send data to the server, for example, creating a new post, file upload, etc. using HTML forms.
-
-3. PUT: Replaces all current representations of the target resource with the uploaded content and we use it modify or update data.
-
-4. DELETE: Removes data
-
-## 💻 Exercises: Day 28
-
-1. Read about API and HTTP
-
-🎉 CONGRATULATIONS ! 🎉
-
-[<< Day 27](../27_Day_Python_with_mongodb/27_python_with_mongodb.md) | [Day 29 >>](../29_Day_Building_API/29_building_API.md)
diff --git a/docs/28_PostgreSQL.md b/docs/28_PostgreSQL.md
new file mode 100644
index 0000000..bac4184
--- /dev/null
+++ b/docs/28_PostgreSQL.md
@@ -0,0 +1 @@
+[PostgreSQL: The world's most advanced open source database](https://www.postgresql.org/)
\ No newline at end of file
diff --git a/docs/29_FastAPI_PostgreAQL.md b/docs/29_FastAPI_PostgreAQL.md
new file mode 100644
index 0000000..97390fe
--- /dev/null
+++ b/docs/29_FastAPI_PostgreAQL.md
@@ -0,0 +1,79 @@
+[tiangolo/full-stack-fastapi-postgresql: Full stack, modern web application generator. Using FastAPI, PostgreSQL as database, Docker, automatic HTTPS and more. (github.com)](https://github.com/tiangolo/full-stack-fastapi-postgresql)
+
+## 文字教程
+
+1. **Squash.io 教程**:此教程解释了如何设置 FastAPI 应用程序与 PostgreSQL 的基础知识。它涵盖了创建同步和异步处理程序,配置 SQLAlchemy 进行数据库交互,并提供了常见数据库操作(如检索、插入、更新和删除数据)的代码片段【8†source】。
+
+2. **Codevoweb 教程**:这个资源提供了使用 Python、FastAPI 和 PostgreSQL 构建 CRUD RESTful API 服务器的逐步指南。它包括有关设置环境和数据库的详细说明,并配置了 JWT 用于身份验证【9†source】。
+
+3. **TutLinks 教程**:此教程重点介绍如何在 FastAPI 中实现异步 REST API 与 PostgreSQL。它提供了添加 CORS 到 FastAPI 的见解,管理应用程序启动和关闭事件,并使用 HTTP 动词创建、更新和检索数据。这是一个全面的指南,用于构建具有分页和 CRUD 功能的笔记应用程序【10†source】。
+
+
+
+## 视频教程
+
+一些关于如何将 FastAPI 与 PostgreSQL 结合使用的视频教程:
+
+1. **"如何使用 PostgreSQL 构建 FastAPI 应用"**:这个视频提供了一个全面的指南,讲述了如何构建一个集成了 PostgreSQL 的 FastAPI 应用。非常适合想要全面了解整个过程的人。
+ - [在 YouTube 上观看](https://www.youtube.com/watch?v=398DuQbQJq0)【16†来源】。
+
+2. **"Fast API 快速课程 | 使用 Postgres、SQL Alchemy、Async 等构建应用程序"**:这是一个速成课程,你可以跟随它来构建一个使用 FastAPI、PostgreSQL、SQL Alchemy 和 Async 的学习管理系统 API。
+ - [在 YouTube 上观看](https://www.youtube.com/watch?v=gQTRsZpR7Gw)【17†来源】。
+
+3. **"使用 Fastapi 和 PostgreSQL 创建 RESTful API CRUD"**:这个教程重点介绍了如何创建一个简单的项目来连接 PostgreSQL 和 FastAPI,涵盖了 RESTful API 开发和 CRUD 操作。
+ - [在 YouTube 上观看](https://www.youtube.com/watch?v=d_ugoWsvGLI)【18†来源】。
+
+4. **"结合使用 FastAPI、PostgreSQL 和 Docker"**:如果你有兴趣在 FastAPI 和 PostgreSQL 旁边使用 Docker,这个视频是一个很好的资源。它涵盖了使用 FastAPI 和 PostgreSQL 数据库在 Docker 容器中设置基本 API 的过程。
+ - [在 YouTube 上观看](https://www.youtube.com/watch?v=2X8B_X2c27Q)【19†来源】。
+
+5. **"使用 FastAPI 和 SQLAlchemy 与 PostgreSQL 数据库"**:本教程介绍了如何使用 FastAPI 连接 PostgreSQL 数据库,并使用 SQLAlchemy 实现基本的 CRUD 功能。
+ - [在 YouTube 上观看](https://www.youtube.com/watch?v=Lj7ivxUvSog)【20†来源】。
+
+这些教程应该能为你在构建 FastAPI 和 PostgreSQL 应用程序方面提供坚实的基础和实用的见解。
+
+---
+
+## 需要SQLAlchemy吗
+
+不一定需要使用 SQLAlchemy 来在 FastAPI 中连接到 PostgreSQL 数据库。虽然 SQLAlchemy 是一个非常流行的 ORM(对象关系映射)工具,它可以简化数据库操作并提供额外的抽象层,但它不是必需的。你可以直接使用异步数据库驱动(如 `asyncpg`)来执行 SQL 查询。
+
+如果你选择不使用 ORM(如 SQLAlchemy),你将直接编写原始 SQL 语句来与数据库进行交互。这种方法可以让你拥有更细粒度的控制,尤其是在处理复杂的查询和数据库操作时。然而,它也意味着你需要自己处理一些额外的工作,比如构造查询和解析结果。
+
+以下是一个使用 `asyncpg` 而不是 SQLAlchemy 连接到 PostgreSQL 的示例:
+
+1. **安装依赖项**:
+ ```bash
+ pip install fastapi uvicorn asyncpg
+ ```
+
+2. **设置数据库连接**:
+ ```python
+ import asyncpg
+ from fastapi import FastAPI
+
+ app = FastAPI()
+
+ @app.on_event("startup")
+ async def startup():
+ app.state.db = await asyncpg.connect(user='your_username', password='your_password',
+ database='your_database', host='127.0.0.1')
+
+ @app.on_event("shutdown")
+ async def shutdown():
+ await app.state.db.close()
+ ```
+
+3. **在 FastAPI 路径操作中执行 SQL 查询**:
+ ```python
+ @app.get("/items/")
+ async def read_items():
+ rows = await app.state.db.fetch("SELECT * FROM items")
+ return rows
+ ```
+
+4. **运行 FastAPI 应用程序**:
+ ```bash
+ uvicorn your_fastapi_file:app --reload
+ ```
+
+这种方法更接近于底层数据库操作,可能更适合那些对 SQL 很熟悉并且希望直接控制他们数据库交互的用户。不过,如果你的应用程序需要复杂的数据模型或者你希望利用 ORM 提供的便利性和安全性,那么使用 SQLAlchemy 或者其他 ORM 工具可能是更好的选择。
\ No newline at end of file
diff --git a/docs/29_building_API.md b/docs/29_building_API.md
deleted file mode 100644
index 472b2c4..0000000
--- a/docs/29_building_API.md
+++ /dev/null
@@ -1,502 +0,0 @@
-
-
-[<< Day 28](../28_Day_API/28_API.md) | [Day 29 >>](../30_Day_Conclusions/30_conclusions.md)
-
-![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
-
-- [Day 29](#day-29)
-- [Building API](#building-api)
- - [Structure of an API](#structure-of-an-api)
- - [Retrieving data using get](#retrieving-data-using-get)
- - [Getting a document by id](#getting-a-document-by-id)
- - [Creating data using POST](#creating-data-using-post)
- - [Updating using PUT](#updating-using-put)
- - [Deleting a document using Delete](#deleting-a-document-using-delete)
-- [💻 Exercises: Day 29](#-exercises-day-29)
-
-## Day 29
-
-## Building API
-
-
-In this section, we will cove a RESTful API that uses HTTP request methods to GET, PUT, POST and DELETE data.
-
-RESTful API is an application program interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data. In the previous sections, we have learned about python, flask and mongoDB. We will use the knowledge we acquire to develop a RESTful API using python flask and mongoDB. Every application which has CRUD(Create, Read, Update, Delete) operation has an API to create data, to get data, to update data or to delete data from database.
-
-The browser can handle only get request. Therefore, we have to have a tool which can help us to handle all request methods(GET, POST, PUT, DELETE).
-
-Examples of API
-
-- Countries API: https://restcountries.eu/rest/v2/all
-- Cats breed API: https://api.thecatapi.com/v1/breeds
-
-[Postman](https://www.getpostman.com/) is a very popular tool when it comes to API development. So, if you like to do this section you need to [download postman](https://www.getpostman.com/). An alternative of Postman is [Insomnia](https://insomnia.rest/download).
-
-![Postman](../images/postman.png)
-
-### Structure of an API
-
-An API end point is a URL which can help to retrieve, create, update or delete a resource. The structure looks like this:
-Example:
-https://api.twitter.com/1.1/lists/members.json
-Returns the members of the specified list. Private list members will only be shown if the authenticated user owns the specified list.
-The name of the company name followed by version followed by the purpose of the API.
-The methods:
-HTTP methods & URLs
-
-The API uses the following HTTP methods for object manipulation:
-
-```sh
-GET Used for object retrieval
-POST Used for object creation and object actions
-PUT Used for object update
-DELETE Used for object deletion
-```
-
-Let us build an API which collects information about 30DaysOfPython students. We will collect the name, country, city, date of birth, skills and bio.
-
-To implement this API, we will use:
-
-- Postman
-- Python
-- Flask
-- MongoDB
-
-### Retrieving data using get
-
-In this step, let us use dummy data and return it as a json. To return it as json, will use json module and Response module.
-
-```py
-# let's import the flask
-
-from flask import Flask, Response
-import json
-
-app = Flask(__name__)
-
-@app.route('/api/v1.0/students', methods = ['GET'])
-def students ():
- student_list = [
- {
- 'name':'Asabeneh',
- 'country':'Finland',
- 'city':'Helsinki',
- 'skills':['HTML', 'CSS','JavaScript','Python']
- },
- {
- 'name':'David',
- 'country':'UK',
- 'city':'London',
- 'skills':['Python','MongoDB']
- },
- {
- 'name':'John',
- 'country':'Sweden',
- 'city':'Stockholm',
- 'skills':['Java','C#']
- }
- ]
- return Response(json.dumps(student_list), mimetype='application/json')
-
-
-if __name__ == '__main__':
- # for deployment
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-When you request the http://localhost:5000/api/v1.0/students url on the browser you will get this:
-
-![Get on browser](../images/get_on_browser.png)
-
-When you request the http://localhost:5000/api/v1.0/students url on the browser you will get this:
-
-![Get on postman](../images/get_on_postman.png)
-
-In stead of displaying dummy data let us connect the flask application with MongoDB and get data from mongoDB database.
-
-```py
-# let's import the flask
-
-from flask import Flask, Response
-import json
-import pymongo
-
-
-app = Flask(__name__)
-
-#
-MONGODB_URI='mongodb+srv://asabeneh:your_password@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-
-@app.route('/api/v1.0/students', methods = ['GET'])
-def students ():
-
- return Response(json.dumps(student), mimetype='application/json')
-
-
-if __name__ == '__main__':
- # for deployment
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-By connecting the flask, we can fetch students collection data from the thirty_days_of_python database.
-
-```sh
-[
- {
- "_id": {
- "$oid": "5df68a21f106fe2d315bbc8b"
- },
- "name": "Asabeneh",
- "country": "Finland",
- "city": "Helsinki",
- "age": 38
- },
- {
- "_id": {
- "$oid": "5df68a23f106fe2d315bbc8c"
- },
- "name": "David",
- "country": "UK",
- "city": "London",
- "age": 34
- },
- {
- "_id": {
- "$oid": "5df68a23f106fe2d315bbc8e"
- },
- "name": "Sami",
- "country": "Finland",
- "city": "Helsinki",
- "age": 25
- }
-]
-```
-
-### Getting a document by id
-
-We can access signle document using an id, let's access Asabeneh using his id.
-http://localhost:5000/api/v1.0/students/5df68a21f106fe2d315bbc8b
-
-```py
-# let's import the flask
-
-from flask import Flask, Response
-import json
-from bson.objectid import ObjectId
-import json
-from bson.json_util import dumps
-import pymongo
-
-
-app = Flask(__name__)
-
-#
-MONGODB_URI='mongodb+srv://asabeneh:your_password@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-
-@app.route('/api/v1.0/students', methods = ['GET'])
-def students ():
-
- return Response(json.dumps(student), mimetype='application/json')
-@app.route('/api/v1.0/students/', methods = ['GET'])
-def single_student (id):
- student = db.students.find({'_id':ObjectId(id)})
- return Response(dumps(student), mimetype='application/json')
-
-if __name__ == '__main__':
- # for deployment
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-```sh
-[
- {
- "_id": {
- "$oid": "5df68a21f106fe2d315bbc8b"
- },
- "name": "Asabeneh",
- "country": "Finland",
- "city": "Helsinki",
- "age": 38
- }
-]
-```
-
-### Creating data using POST
-
-We use the POST request method to create data
-
-```py
-# let's import the flask
-
-from flask import Flask, Response
-import json
-from bson.objectid import ObjectId
-import json
-from bson.json_util import dumps
-import pymongo
-from datetime import datetime
-
-
-app = Flask(__name__)
-
-#
-MONGODB_URI='mongodb+srv://asabeneh:your_password@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-
-@app.route('/api/v1.0/students', methods = ['GET'])
-def students ():
-
- return Response(json.dumps(student), mimetype='application/json')
-@app.route('/api/v1.0/students/', methods = ['GET'])
-def single_student (id):
- student = db.students.find({'_id':ObjectId(id)})
- return Response(dumps(student), mimetype='application/json')
-@app.route('/api/v1.0/students', methods = ['POST'])
-def create_student ():
- name = request.form['name']
- country = request.form['country']
- city = request.form['city']
- skills = request.form['skills'].split(', ')
- bio = request.form['bio']
- birthyear = request.form['birthyear']
- created_at = datetime.now()
- student = {
- 'name': name,
- 'country': country,
- 'city': city,
- 'birthyear': birthyear,
- 'skills': skills,
- 'bio': bio,
- 'created_at': created_at
-
- }
- db.students.insert_one(student)
- return ;
-def update_student (id):
-if __name__ == '__main__':
- # for deployment
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-### Updating using PUT
-
-```py
-# let's import the flask
-
-from flask import Flask, Response
-import json
-from bson.objectid import ObjectId
-import json
-from bson.json_util import dumps
-import pymongo
-from datetime import datetime
-
-
-app = Flask(__name__)
-
-#
-MONGODB_URI='mongodb+srv://asabeneh:your_password@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-
-@app.route('/api/v1.0/students', methods = ['GET'])
-def students ():
-
- return Response(json.dumps(student), mimetype='application/json')
-@app.route('/api/v1.0/students/', methods = ['GET'])
-def single_student (id):
- student = db.students.find({'_id':ObjectId(id)})
- return Response(dumps(student), mimetype='application/json')
-@app.route('/api/v1.0/students', methods = ['POST'])
-def create_student ():
- name = request.form['name']
- country = request.form['country']
- city = request.form['city']
- skills = request.form['skills'].split(', ')
- bio = request.form['bio']
- birthyear = request.form['birthyear']
- created_at = datetime.now()
- student = {
- 'name': name,
- 'country': country,
- 'city': city,
- 'birthyear': birthyear,
- 'skills': skills,
- 'bio': bio,
- 'created_at': created_at
-
- }
- db.students.insert_one(student)
- return
-@app.route('/api/v1.0/students/', methods = ['PUT']) # this decorator create the home route
-def update_student (id):
- query = {"_id":ObjectId(id)}
- name = request.form['name']
- country = request.form['country']
- city = request.form['city']
- skills = request.form['skills'].split(', ')
- bio = request.form['bio']
- birthyear = request.form['birthyear']
- created_at = datetime.now()
- student = {
- 'name': name,
- 'country': country,
- 'city': city,
- 'birthyear': birthyear,
- 'skills': skills,
- 'bio': bio,
- 'created_at': created_at
-
- }
- db.students.update_one(query, student)
- # return Response(dumps({"result":"a new student has been created"}), mimetype='application/json')
- return
-def update_student (id):
-if __name__ == '__main__':
- # for deployment
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-### Deleting a document using Delete
-
-```py
-# let's import the flask
-
-from flask import Flask, Response
-import json
-from bson.objectid import ObjectId
-import json
-from bson.json_util import dumps
-import pymongo
-from datetime import datetime
-
-
-app = Flask(__name__)
-
-#
-MONGODB_URI='mongodb+srv://asabeneh:your_password@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
-client = pymongo.MongoClient(MONGODB_URI)
-db = client['thirty_days_of_python'] # accessing the database
-
-@app.route('/api/v1.0/students', methods = ['GET'])
-def students ():
-
- return Response(json.dumps(student), mimetype='application/json')
-@app.route('/api/v1.0/students/', methods = ['GET'])
-def single_student (id):
- student = db.students.find({'_id':ObjectId(id)})
- return Response(dumps(student), mimetype='application/json')
-@app.route('/api/v1.0/students', methods = ['POST'])
-def create_student ():
- name = request.form['name']
- country = request.form['country']
- city = request.form['city']
- skills = request.form['skills'].split(', ')
- bio = request.form['bio']
- birthyear = request.form['birthyear']
- created_at = datetime.now()
- student = {
- 'name': name,
- 'country': country,
- 'city': city,
- 'birthyear': birthyear,
- 'skills': skills,
- 'bio': bio,
- 'created_at': created_at
-
- }
- db.students.insert_one(student)
- return
-@app.route('/api/v1.0/students/', methods = ['PUT']) # this decorator create the home route
-def update_student (id):
- query = {"_id":ObjectId(id)}
- name = request.form['name']
- country = request.form['country']
- city = request.form['city']
- skills = request.form['skills'].split(', ')
- bio = request.form['bio']
- birthyear = request.form['birthyear']
- created_at = datetime.now()
- student = {
- 'name': name,
- 'country': country,
- 'city': city,
- 'birthyear': birthyear,
- 'skills': skills,
- 'bio': bio,
- 'created_at': created_at
-
- }
- db.students.update_one(query, student)
- # return Response(dumps({"result":"a new student has been created"}), mimetype='application/json')
- return
-@app.route('/api/v1.0/students/', methods = ['PUT']) # this decorator create the home route
-def update_student (id):
- query = {"_id":ObjectId(id)}
- name = request.form['name']
- country = request.form['country']
- city = request.form['city']
- skills = request.form['skills'].split(', ')
- bio = request.form['bio']
- birthyear = request.form['birthyear']
- created_at = datetime.now()
- student = {
- 'name': name,
- 'country': country,
- 'city': city,
- 'birthyear': birthyear,
- 'skills': skills,
- 'bio': bio,
- 'created_at': created_at
-
- }
- db.students.update_one(query, student)
- # return Response(dumps({"result":"a new student has been created"}), mimetype='application/json')
- return ;
-@app.route('/api/v1.0/students/', methods = ['DELETE'])
-def delete_student (id):
- db.students.delete_one({"_id":ObjectId(id)})
- return
-if __name__ == '__main__':
- # for deployment
- # to make it work for both production and development
- port = int(os.environ.get("PORT", 5000))
- app.run(debug=True, host='0.0.0.0', port=port)
-```
-
-## 💻 Exercises: Day 29
-
-1. Implement the above example and develop [this](https://thirtydayofpython-api.herokuapp.com/)
-
-🎉 CONGRATULATIONS ! 🎉
-
-[<< Day 28](../28_Day_API/28_API.md) | [Day 30 >>](../30_Day_Conclusions/30_conclusions.md)
diff --git a/docs/30_conclusions.md b/docs/30_conclusions.md
deleted file mode 100644
index e8865fc..0000000
--- a/docs/30_conclusions.md
+++ /dev/null
@@ -1,40 +0,0 @@
-