Code Monkey home page Code Monkey logo

wpcodevo / fastapi_mongodb Goto Github PK

View Code? Open in Web Editor NEW
80.0 4.0 28.0 30 KB

This article will teach you how to create a CRUD RESTful API with Python, FastAPI, PyMongo, MongoDB, and Docker-compose to perform the basic Create/Read/Update/Delete operations against a database.

Home Page: https://codevoweb.com/crud-restful-api-server-with-python-fastapi-and-mongodb

Shell 4.50% Makefile 0.71% Python 66.99% HTML 27.81%
fastapi fastapi-crud fastapi-framework jwt jwt-authentication mongodb pydantic pydantic-models rest-api uvicorn

fastapi_mongodb's Introduction

RESTful API with Python, FastAPI, Pydantic, and MongoDB

1. API with Python, FastAPI, and MongoDB: JWT Authentication

This article will teach you how to add JSON Web Token (JWT) authentication to your FastAPI app using PyMongo, Pydantic, FastAPI JWT Auth package, and Docker-compose.

API with Python, FastAPI, and MongoDB: JWT Authentication

Topics Covered

  • How to Setup FastAPI with MongoDB
  • Starting the FastAPI Server
  • Set up Environment Variables with Pydantic
  • Connect to the MongoDB Database
  • Creating the Schemas with Pydantic
  • Create Serializers for the MongoDB BSON Documents
  • Password Management in FastAPI
  • Creating Utility Functions to Sign and Verify JWTs
  • Creating the Authentication Controllers in FastAPI
    • User Registration Handler
    • User Sign-in Handler
    • Refresh Access Token Handler
    • Sign out User Handler
  • How to Protect Private Routes
  • Creating a User Handler
  • Adding the API Routes and CORS
  • Testing the API with Postman

Read the entire article here: https://codevoweb.com/api-with-python-fastapi-and-mongodb-jwt-authentication

2. Build API with Python & FastAPI: SignUp User and Verify Email

This article will teach you how to send HTML Emails with Python, FastAPI, PyMongo, MongoDB, Jinja2, and Docker. Also, you will learn how to use Jinja2 to generate different HTML templates.

Build API with Python & FastAPI: SignUp User and Verify Email

Topics Covered

  • Send HTML Emails with Jinja2 & FastAPI Example
  • Creating the SMTP Provider Account
  • Edit the Environment Variables File
  • Validating the Environment Variables with Pydantic
  • Creating the HTML Email Templates in FastAPI
  • Creating the SMTP Email Sender
  • Sending the HTML Emails in FastAPI
  • Update the SignUp Controller
  • Create a Handler to Validate the Verification Code

Read the entire article here: https://codevoweb.com/api-with-python-fastapi-signup-user-and-verify-email

3. CRUD RESTful API Server with Python, FastAPI, and MongoDB

This article will teach you how to create a CRUD RESTful API with Python, FastAPI, PyMongo, MongoDB, and Docker-compose to perform the basic Create/Read/Update/Delete operations against a database.

CRUD RESTful API Server with Python, FastAPI, and MongoDB

Topics Covered

  • Python, FastAPI, MongoDB CRUD API Overview
  • Setting up FastAPI with MongoDB
    • Installing FastAPI
  • Running the FastAPI Server
  • Loading Environment Variables with Pydantic
  • Connecting to the MongoDB Database Server
  • Creating the Schemas with Pydantic
  • Serializers for the MongoDB Documents
  • Creating the API Route Controllers
    • Get All Posts Controller
    • Create New Post Controller
    • Update Post Controller
    • Get Single Post Controller
    • Delete Post Controller
  • Add the Routes to the FastAPI Middleware Stack

Read the entire article here: https://codevoweb.com/crud-restful-api-server-with-python-fastapi-and-mongodb

fastapi_mongodb's People

Contributors

wpcodevo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fastapi_mongodb's Issues

Error running

Hi, I am trying to test the example but I have the following errors:

`INFO: Started reloader process [902] using WatchFiles
Connected to MongoDB...
Process SpawnProcess-1:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/uvicorn/_subprocess.py", line 76, in subprocess_started
target(sockets=sockets)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/uvicorn/server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/uvicorn/server.py", line 67, in serve
config.load()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/uvicorn/config.py", line 477, in load
self.loaded_app = import_from_string(self.app)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/uvicorn/importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "", line 883, in exec_module
File "", line 241, in _call_with_frames_removed
.......

.......
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pymongo/auth.py", line 475, in _authenticate_default
return _authenticate_scram(credentials, sock_info, "SCRAM-SHA-1")
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pymongo/auth.py", line 201, in _authenticate_scram
res = sock_info.command(source, cmd)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pymongo/pool.py", line 767, in command
return command(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pymongo/network.py", line 166, in command
helpers._check_command_response(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pymongo/helpers.py", line 181, in _check_command_response
raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: Authentication failed., full error: {'ok': 0.0, 'errmsg': 'Authentication failed.', 'code': 18, 'codeName': 'AuthenticationFailed'}`

I have also tried connect with a MongoDB Atlas but also run with errors. Please, any help?

Thank you in advance for the help.

Add Settings

Add settings for PASSWORD_MIN_LEN and EMAIL_STARTTLS.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.