Project Structure
This section provides an overview of the BlazingAPI Project Structure.
The Project Structure
section provides an overview of the key files and directories in a BlazingAPI project, helping you understand and organize your code effectively.
Overview
Welcome to the Project Structure
section. Here, you'll find all the information you need to get started with organizing your BlazingAPI application.
Project Files
In a typical BlazingAPI project, you'll find the following core files:
main.py
views.py
models.py
settings.py
db.sqlite3
main.py
This is the entry point for running your BlazingAPI application. It imports the required run
method from BlazingAPI's server module and executes it.
BlazingAPI will run the server on the default port 8000
. You can change the port by passing the port
argument to the run
method.
The server will be served using Gunicorn if the local machine is running on a Unix-based operating system. Otherwise, it will be served using the built-in http.server
module.
# main.py
from blazingapi.server import run
if __name__ == "__main__":
run()
views.py
This file contains the view functions that handle incoming requests and return responses. Each view function is a Python function that takes a request object as an argument and returns a response object.
# views.py
from blazingapi.app import app
from blazingapi.response import Response
@app.get("/index")
def index(request):
return Response(body={"message": "Hello, world!"})
models.py
This file contains the data models that represent the structure of your application's data. You can define classes that inherit from the Model
class provided by BlazingAPI to create data models.
File comes empty by default but you can define your models as shown below.
# models.py
from blazingapi.orm.models import Model
from blazingapi.orm.fields import VarCharField
class Article(Model):
title = VarCharField(max_length=256)
content = TextField()
settings.py
This file contains the configuration settings for your BlazingAPI application. You can define settings such as middleware classes, view files and database settings.
DEBUG = True
VIEW_FILES = [
"blazingapi.auth.views",
"views",
]
MODEL_FILES = [
"blazingapi.auth.models",
"models"
]
MIDDLEWARE_CLASSES = [
"blazingapi.security.middleware.CorsMiddleware",
"blazingapi.security.middleware.XFrameOptionsMiddleware",
"blazingapi.auth.middleware.BearerAuthenticationMiddleware",
]
DB_CONNECTION = {
"driver": "sqlite",
"database": "db.sqlite3"
}
LOGIN_ENDPOINT = "/api/auth/login"
REGISTER_ENDPOINT = "/api/auth/register"
ME_ENDPOINT = "/api/auth/me"
X_FRAME_OPTIONS = "DENY"
CORS_ALLOWED_ORIGINS = ["*"]
CORS_ALLOWED_METHODS = ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
CORS_ALLOWED_HEADERS = ["Content-Type", "Authorization"]
db.sqlite3
This file is the default SQLite database file used by BlazingAPI. You can use this file to store your application's data.
For production you can change settings.py
to use a different database.