Sign inSign up

yezz123/dogeapi

By yezz123

•Updated over 5 years ago

API with high performance built with FastAPI, help to improve connection with your Backend Side.

Image
0

1.0K

yezz123/dogeapi repository overview

Star Badge

⁠DogeAPI

API with high performance built with FastAPI & SQLAlchemy, help to improve connection with your Backend Side to create a simple blog and Cruds with OAuth2PasswordBearer ⛏

⁠Getting Started

⁠Prerequisites
  • Python 3.8.6 or higher
  • FastAPI
  • Docker
⁠Project setup
# clone the repo
$ git clone https://github.com/yezz123/DogeAPI

# move to the project folder
$ cd DogeAPI
⁠Creating virtual environment
  • Install pipenv a global python project pip install pipenv
  • Create a virtual environment for this project
# creating pipenv environment for python 3
$ pipenv --three

# activating the pipenv environment
$ pipenv shell

# if you have multiple python 3 versions installed then
$ pipenv install -d --python 3.8

# install all dependencies (include -d for installing dev dependencies)
$ pipenv install -d
⁠Running the Application
  • To run the Main⁠ we need to use uvicorn⁠ a lightning-fast ASGI server implementation, using uvloop and httptools.
# Running the application using uvicorn
$ uvicorn main:app

## To run the Application under a reload enviromment use -- reload
$ uvicorn main:app --reload
⁠Configured Enviromment
⁠Database
  • To Provide a good and fast work, i choose a SQLite Database using SQLAlchemy.
  • If you want to configure the Database with an other Provider like MySQL or PostgreSQL you can change the Database_URL here :
# here you need to inster the  URI that should be used for the connection.
SQLALCHEMY_DATABASE_URL = 'sqlite:///blog.db'
  • For Example :
SQLALCHEMY_DATABASE_URL = 'mysql://username:password@server/blog'
⁠Models
  • Here for the Models.py⁠, i create 2 tables based on the requirements for this project blogs and users
class Blog(Base):
    __tablename__ = "blogs"
    id = Column(Integer, primary_key=True, index=True)
    title = Column(String)
    body = Column(String)
    user_id = Column(Integer, ForeignKey("users.id"))
    creator = relationship("User", back_populates="blogs")
class User(Base):
    __tablename__ = "users"
    id = Column(Integer, primary_key=True, index=True)
    name = Column(String)
    email = Column(String)
    password = Column(String)
    blogs = relationship("Blog", back_populates="creator")
⁠Token
  • Set environment variables as the Secret Key and Time Expire for Token, i made it in an easy way to get it.
  • Change the .env.sample to .env then insert you String Secret_Key and ACCESS_TOKEN_EXPIRE_MINUTES.
  • you can generate the String using openssl rand -hex 32.

⁠Running the Docker Container

  • We have the Dockerfile created in above section. Now, we will use the Dockerfile to create the image of the FastAPI app and then start the FastAPI app container.
$ docker build
  • list all the docker images and you can also see the image dogeapi:latest in the list.
$ docker images
  • run the application at port 5000. The various options used are:
  • -p: publish the container's port to the host port.
  • -d: run the container in the background.
  • -i: run the container in interactive mode.
  • -t: to allocate pseudo-TTY.
  • --name: name of the container
$ docker container run -p 5000:5000 -dit --name DOGEAPI dogeapi:latest
  • Check the status of the docker container
$ docker container ps

⁠Preconfigured Packages

Includes preconfigured packages to kick start DogeAPI by just setting appropriate configuration.

PackageUsage
uvicorn⁠a lightning-fast ASGI server implementation, using uvloop and httptools.
Python-Jose⁠a JavaScript Object Signing and Encryption implementation in Python.
SQLAlchemy⁠is the Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL.
starlette⁠a lightweight ASGI framework/toolkit, which is ideal for building high performance asyncio services.
passlib⁠a password hashing library for Python 2 & 3, which provides cross-platform implementations of over 30 password hashing algorithms
bcrypt⁠Good password hashing for your software and your servers.
python-multipart⁠streaming multipart parser for Python.

yapf packages for linting and formatting

⁠Contributing

  • Join the DOGEAPI Creator and Contribute to the Project if you have any enhancement or add-ons to create a good and Secure Project, Help any User to Use it in a good and simple way.
  • Check all information here at docs's Folder⁠ to understand to how to contribute or to Read the Code of Conduct.

⁠License

This project is licensed under the terms of the MIT license.

Tag summary

Content type

Image

Digest

Size

486 MB

Last updated

over 5 years ago

docker pull yezz123/dogeapi