Posts

Showing posts from May, 2025

Project 3 overview

Image
 Project 3 Project three we will be switching our focus to TODOS instead of BOOKS New information will include: Full SQL Database SQLite - simple easy and embedded database application Postgres - Production RDBMS MySQL - Production RDBMS Authentication - by using JWT (able to create users with username and password for login) Authorization - Roles and Responsibilities according to user type. Hashing Passwords Creating a Todo Table We will create new TODO Table Models for our application We will be using these Todos to save records throughout this project. Architectural diagram for it:

Status Codes | HTTP Exceptions | Explicit Status Code Responses

Image
 Status Codes An HTTP Status Code is used to help the Client (the user or system submitting data to the server) to understand what happened on the server side application. Status Codes are international standards on how a Client/Server should handle the result of a request. It allows everyone who sends a request to know if their submission was successful or not. Status Codes Series and their meanings: 2xx Successful Status Codes: 4xx Client Errors Status Codes: 5xx Server Status Codes: There are many more error codes which can find and can understand their meanings above one are the most common one. HTTP Exceptions Here we will use HTTP Exception package to highlight the error of file not found and will terminate the application. Code: from fastapi import FastAPI , Path , Query , HTTPException from books3 import Book from datavalidatorhelper import BookRequest app = FastAPI () BOOKS = [     Book ( id = 1 , title = "DSA with Java" ,        ...

Path Parameter Data Validation | Query Parameter Data Validation

Image
 Path Parameter Data Validation Here we will try to put validation on each API endpoint we have created in FastAPI. Parts which we will try to validate is: If there is no book then are we returning any message as confirmation of validation? return desired message if your logic not executed as final return statement to validate your API endpoint run in place of showing null in output box or no message at output. How to validate input parameter of the method? We need to import path from FastAPI to implement it at the time of method definition to provide input constraints to be checked. @ app . get ( "/books/ {book_id} " ) async def read_book_by_id ( book_id : int = Path ( gt = 0 )): # it will make sure that index will start from 1.     for book in BOOKS :         if book . id == book_id :             return book     return { "message" : "book not found" } Code:  from fastapi import FastAPI , Bod...