Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SampleCRUD

A simple RESTful CRUD API for managing tasks, built with Express.js and documented with Swagger UI.

Why SQLite

SQLite was chosen because it is a single-file database, requires zero server setup, and keeps data on disk so task state survives app restarts.

Database File Location

  • Database file: db/tasks.db
  • It is created automatically when the app opens the database.
  • This file is usually git-ignored so each clone starts with a fresh local dataset.

Install & Run

npm test

The server starts on http://localhost:3000. Open http://localhost:3000/docs for interactive Swagger UI.

Endpoints

Method Endpoint Description Body
Method Endpoint Description Request Body
---------- --------------- -------------------------- -----------------------------
GET /tasks List all tasks
GET /tasks/:id Get a task by ID
POST /tasks Create a new task { "title": "Buy milk" }
PUT /tasks/:id Update a task { "title": "...", "done": true }
DELETE /tasks/:id Delete a task

Example Outputs

1. GET /tasks (List all tasks)

HTTP/1.1 200 OK
Content-Type: application/json

[
  {"id": 1, "title": "Learn Express", "done": false},
  {"id": 2, "title": "Build a CRUD API", "done": false},
  {"id": 3, "title": "Push to GitHub", "done": true}
]

GET /tasks - List all tasks

2. POST /tasks (Create a new task)

HTTP/1.1 201 Created
Content-Type: application/json

{"title": "Naming mg git message"}

POST /tasks - Create a new task

3. GET /tasks/:id (Get a single task)

HTTP/1.1 200 OK
Content-Type: application/json

{"id": 1, "title": "Learn Express", "done": false}

GET /tasks/:id - Get a single task

4. PUT /tasks/:id (Update a task)

HTTP/1.1 200 OK
Content-Type: application/json

{"id": 2, "title": "Pooping in the toilet", "done": false}

PUT /tasks/:id - Update a task

5. DELETE /tasks/:id (Delete a task)

HTTP/1.1 204 No Content

DELETE /tasks/:id - Delete a task

Swagger UI

Swagger UI

Try it out at http://localhost:3000/docs for interactive testing.

DB Browser Screenshot

Screenshot of tasks.db opened in DB Browser for SQLite:

DB Browser - tasks.db

Stage 4 SQL Example

One SQL query used in Stage 4 verification:

SELECT id, title, done FROM tasks ORDER BY id;

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages