Skip to content

rahmaaismail/python-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š Book Review API

API Preview

A RESTful Book Review API built with Flask, Flask-RESTful, and Flasgger, using Airtable as a lightweight database and deployed on Render.


πŸ”— Live API

Swagger Documentation:
https://ri-book-review-api.onrender.com/apidocs

πŸš€ Overview

This project is a backend API that allows users to:

  • Add book reviews
  • Retrieve all reviews
  • Sort and limit results
  • Process text through utility endpoints (uppercase + transformations)

It demonstrates core backend engineering concepts including:

  • REST API design
  • External database integration (Airtable)
  • Environment variable management
  • API documentation using Swagger (Flasgger)
  • Cloud deployment (Render)
  • Basic API testing via Python scripts

🧰 Tech Stack

  • Python 3
  • Flask
  • Flask-RESTful
  • Flasgger (Swagger UI)
  • Airtable API
  • Gunicorn
  • Render

πŸ“¦ Project Structure

.
β”œβ”€β”€ app.py                   # Main Flask application
β”œβ”€β”€ book_review.py          # Airtable integration layer
β”œβ”€β”€ api_request_test.py     # Manual API testing script
β”œβ”€β”€ requirements.txt        # Dependencies
└── README.md

πŸ” Environment Variables

This project requires an Airtable API key.

Set it in your environment:

AIRTABLE=your_airtable_api_key

πŸ“‘ Base URL

https://ri-book-review-api.onrender.com

πŸ“˜ API Endpoints


βž• Add a Book Review

POST /post_review

Adds a new book review to Airtable.

Request Body:

{
  "book": "The Alchemist",
  "rating": 9,
  "notes": "A meaningful philosophical journey"
}

Required Fields:

  • book (string)
  • rating (integer)

Response:

{
  "message": "Book review added successfully"
}

πŸ“š Get All Reviews

GET /all_reviews

Returns all book reviews stored in Airtable.

Query Parameters:

  • sort: ASC | DESC (optional)
  • max_records: integer (optional, default 10)

Example:

/all_reviews?sort=DESC&max_records=5

πŸ”  Uppercase Text

GET /uppercase

Query:

  • text (required)

Example:

/uppercase?text=hello

Response:

{
  "text": "HELLO"
}

πŸ” Process Text

GET /process

Query Parameters:

  • text (required)
  • duplication_factor (optional)
  • capitalization (UPPER | LOWER | NONE)

πŸ§ͺ API Testing Script (IMPORTANT)

This project includes a manual API testing file:

πŸ“„ api_request_test.py

This script is used to test deployed endpoints directly using Python.

Example Usage:

import requests

BASE_URL = "https://ri-book-review-api.onrender.com"

url = f"{BASE_URL}/all_reviews"

params = {
    "max_records": 3,
    "sort": "DESC"
}

response = requests.get(url, params=params)

print(response.status_code)
print(response.json())

Why this exists:

  • Quick sanity check for deployed API
  • Helps debug Airtable connection issues
  • Verifies GET/POST requests without Swagger UI
  • Useful for development + deployment testing

πŸ—„οΈ Database

Uses Airtable to store:

  • Book title
  • Rating
  • Notes
  • Timestamp

πŸ“– Swagger Documentation

Interactive API docs available at:

https://ri-book-review-api.onrender.com/apidocs

πŸš€ Deployment

Deployed on Render with:

  • Gunicorn WSGI server
  • Environment variables configured in dashboard
  • Auto deployment from GitHub

⚠️ Common Issues

  • Missing AIRTABLE key β†’ API fails
  • Invalid JSON body β†’ POST request fails
  • Render cold start β†’ first request may be slow
  • Ensure correct endpoint URLs when testing

πŸ™Œ Credits

Inspired by Keith Galli’s Flask API tutorial series.


πŸ“Œ Future Improvements

  • Add authentication (API keys / JWT)
  • Add update/delete endpoints
  • Add pagination for reviews
  • Switch Airtable β†’ PostgreSQL
  • Add automated tests (pytest + CI pipeline)
  • Improve validation + error handling

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages