Skip to content

Latest commit

ย 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Notes Keeper API โ€” Basic

A simple REST API built with Python, Flask, and SQLite for creating, reading, updating, and deleting short text notes.

This project is designed as a beginner-friendly introduction to building APIs with Flask and working with a SQLite database using Python's built-in sqlite3 module.

๐Ÿ“Œ Project Overview

The Notes Keeper API provides a small but complete backend application with:

  • Flask REST API
  • SQLite database
  • Single notes table
  • CRUD operations
  • JSON request and response handling
  • HTTP status codes
  • Parameterized SQL queries
  • Flask's built-in test client

The project intentionally keeps the architecture simple so that the fundamental API โ†’ database โ†’ response workflow becomes clear.

๐Ÿ› ๏ธ Tech Stack

  • Python 3
  • Flask
  • SQLite
  • sqlite3 โ€” Python's built-in SQLite database module
  • JSON โ€” API request/response format

๐Ÿ“‚ Project Structure

notes-api/
โ”‚
โ”œโ”€โ”€ 01_basic_notes_api.ipynb
โ”œโ”€โ”€ notes_basic.db
โ””โ”€โ”€ README.md

notes_basic.db is created by the application when the database is initialized.

๐Ÿš€ Getting Started

1. Clone the repository

git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git
cd YOUR-REPOSITORY

2. Install Flask

Install Flask using pip:

pip install flask

Or:

python -m pip install flask

3. Run the Notebook

Open the notebook:

01_basic_notes_api.ipynb

Run the cells from top to bottom.

The notebook initializes the SQLite database, creates the notes table, registers the Flask routes, and tests the API using Flask's built-in test client.

๐Ÿ—„๏ธ Database

The application uses a SQLite database:

notes_basic.db

The database contains one table:

CREATE TABLE notes (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    content TEXT NOT NULL,
    created_at TEXT DEFAULT CURRENT_TIMESTAMP
);

Table Fields

Field Type Description
id INTEGER Unique automatically generated note ID
content TEXT Text content of the note
created_at TEXT Timestamp when the note was created

๐Ÿ”Œ API Endpoints

The API contains five endpoints.

Method Endpoint Description
GET /notes Get all notes
GET /notes/<id> Get one note
POST /notes Create a new note
PUT /notes/<id> Update an existing note
DELETE /notes/<id> Delete a note

1. Get All Notes

Request

GET /notes

Response

[
    {
        "id": 2,
        "content": "Walk the dog",
        "created_at": "2026-08-11 05:23:03"
    },
    {
        "id": 1,
        "content": "Buy milk",
        "created_at": "2026-08-11 05:23:03"
    }
]

Notes are returned with the newest note first.

2. Get a Single Note

Request

GET /notes/1

Response

{
    "id": 1,
    "content": "Buy milk",
    "created_at": "2026-08-11 05:23:03"
}

If the requested note does not exist, the API returns:

404 Not Found

3. Create a Note

Request

POST /notes

JSON Body

{
    "content": "Learn Flask"
}

Response

{
    "id": 3,
    "content": "Learn Flask"
}

Status Code

201 Created

The API uses 201 Created because a new note has been successfully created.

If content is missing:

400 Bad Request

4. Update a Note

Request

PUT /notes/1

JSON Body

{
    "content": "Learn Flask deeply"
}

Response

{
    "id": 1,
    "content": "Learn Flask deeply"
}

Status Code

200 OK

If the note does not exist:

404 Not Found

5. Delete a Note

Request

DELETE /notes/1

If the note is successfully deleted:

204 No Content

The response body is empty because there is no additional information that needs to be returned.

If the note does not exist:

404 Not Found

๐Ÿ” SQL Injection Protection

Database values are passed using SQLite parameterized queries.

For example:

conn.execute(
    "SELECT * FROM notes WHERE id = ?",
    (note_id,)
)

Instead of directly inserting values into SQL strings.

This keeps user-provided values separate from the SQL statement and avoids unsafe string-based SQL construction.

๐Ÿ”„ API Request Flow

The basic application follows this flow:

Client
   โ”‚
   โ”‚ HTTP Request
   โ–ผ
Flask Route
   โ”‚
   โ–ผ
Database Connection
   โ”‚
   โ–ผ
SQL Query
   โ”‚
   โ–ผ
SQLite Database
   โ”‚
   โ–ผ
Query Result
   โ”‚
   โ–ผ
JSON Response
   โ”‚
   โ–ผ
Client

The core development loop is:

Connect
   โ†“
Query
   โ†“
Commit (when changing data)
   โ†“
Convert result to JSON
   โ†“
Return HTTP response

๐Ÿงช Testing

The project uses Flask's built-in test client:

client = app.test_client()

This allows the API to be tested directly without starting a separate web server.

Example โ€” Create a Note

response = client.post(
    "/notes",
    json={"content": "Buy milk"}
)

Example โ€” Get Notes

response = client.get("/notes")

Example โ€” Update

response = client.put(
    "/notes/1",
    json={"content": "Buy oat milk"}
)

Example โ€” Delete

response = client.delete("/notes/2")

๐Ÿ“Š HTTP Status Codes

The project demonstrates several important HTTP status codes:

Status Meaning Used For
200 OK Successful GET/PUT
201 Created Successfully creating a note
204 No Content Successfully deleting a note
400 Bad Request Missing required content
404 Not Found Note does not exist

๐Ÿง  Concepts Learned

This project focuses on the fundamentals of backend API development:

  • Flask application setup
  • Flask routes
  • HTTP methods
  • REST API structure
  • JSON requests
  • JSON responses
  • SQLite database connections
  • SQL SELECT
  • SQL INSERT
  • SQL UPDATE
  • SQL DELETE
  • Database transactions
  • commit()
  • fetchone()
  • fetchall()
  • rowcount
  • Parameterized SQL queries
  • HTTP status codes
  • Error handling with abort()
  • Flask test client

๐Ÿ“ˆ CRUD Mapping

The API follows the standard CRUD pattern:

CREATE
POST /notes

READ
GET /notes
GET /notes/<id>

UPDATE
PUT /notes/<id>

DELETE
DELETE /notes/<id>

โš ๏ธ Project Scope

This is intentionally a Basic API.

It currently contains:

  • One database table
  • No table relationships
  • No foreign keys
  • No authentication
  • No authorization
  • No query filtering
  • Basic error handling
  • No pagination

These limitations are intentional so the core Flask + SQLite workflow can be learned first.

๐Ÿ”ฎ Next Steps

The next version of the project can build on this same architecture.

Intermediate Version

The planned intermediate project adds:

  • Query filtering such as:
?done=true
  • Global Flask error handling
  • Consistent JSON error responses

Advanced Version

The advanced project introduces:

  • A second database table
  • Foreign keys
  • Relationships between tables
  • Queries involving multiple tables

This allows the project to progress from a single-table API toward a more realistic backend architecture.

๐ŸŽฏ Learning Goal

The main goal of this project is to understand the complete backend cycle:

HTTP Request
      โ†“
Flask
      โ†“
Route
      โ†“
Python
      โ†“
SQLite
      โ†“
SQL
      โ†“
Database Result
      โ†“
JSON
      โ†“
HTTP Response

Once this cycle becomes familiar, more advanced backend concepts such as validation, authentication, filtering, relationships, PostgreSQL, and larger application architectures can be added on top.

๐Ÿ‘จโ€๐Ÿ’ป Author

Developed as a learning project for understanding Flask REST APIs and SQLite database integration.


โญ Project Summary

Notes Keeper API is a minimal Flask REST API that demonstrates how a Python backend receives HTTP requests, performs SQL operations on a SQLite database, and returns JSON responses.

It provides a complete beginner-level implementation of CRUD operations using Flask + SQLite.

About

Today i built a new notes api useful for get,push also represent my crud in flask

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages