Skip to content

lumanaai/mcp_playground

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NestJS Persons API

A simple NestJS application that provides CRUD APIs for managing persons with in-memory storage.

Features

  • Create Person: Add a new person with name, gender, and date of birth
  • Get Person by ID: Retrieve a specific person by their unique ID
  • Get All Persons: Retrieve all persons in the system
  • Delete Person by ID: Remove a person from the system

Person Schema

Each person has the following properties:

  • id: Number (1-1000, auto-generated sequentially)
  • name: String (required)
  • gender: String (required, must be 'male', 'female', or 'other')
  • dateOfBorn: Number (required, birth year between 1900 and current year)

Installation

  1. Install dependencies:
npm install
  1. Start the application:
npm run start:dev

The application will run on http://localhost:3000

Note: The start:dev command automatically kills any process running on port 3000 before starting to prevent "port already in use" errors.

API Endpoints

1. Create Person

  • Method: POST
  • URL: /persons
  • Body:
{
  "name": "John Doe",
  "gender": "male",
  "dateOfBorn": 1990
}
  • Response: Returns the created person with generated numeric ID (1-1000)

2. Get All Persons

  • Method: GET
  • URL: /persons
  • Response: Returns array of all persons

3. Get Person by ID

  • Method: GET
  • URL: /persons/:id
  • Response: Returns the person with specified ID

4. Update Person

  • Method: PUT
  • URL: /persons/:id
  • Body: (All fields are optional)
{
  "name": "Jane Doe",
  "gender": "female",
  "dateOfBorn": 1992
}
  • Response: Returns the updated person

5. Delete Person

  • Method: DELETE
  • URL: /persons/:id
  • Response: 204 No Content

Example Usage with curl

Create a person:

curl -X POST http://localhost:3000/persons \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Doe",
    "gender": "male",
    "dateOfBorn": 1990
  }'

Get all persons:

curl http://localhost:3000/persons

Get person by ID:

curl http://localhost:3000/persons/1

Update a person:

curl -X PUT http://localhost:3000/persons/1 \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Smith",
    "dateOfBorn": 1991
  }'

Delete a person:

curl -X DELETE http://localhost:3000/persons/1

Data Storage

This application uses persistent file storage with the following features:

  • Data is automatically saved to data/persons.json after every create, update, or delete operation
  • Data is automatically loaded from the file when the application starts
  • Data persists between application restarts - no data loss!
  • No database setup is required - uses simple JSON file storage
  • The data/ directory is created automatically if it doesn't exist

File Location

  • File Path: data/persons.json (in the project root)
  • Format: Pretty-printed JSON with proper Date object handling
  • Auto-backup: Data is saved immediately after every operation

Development Scripts

  • npm run start: Start the application
  • npm run start:dev: Start in development mode with auto-reload
  • npm run start:debug: Start in debug mode
  • npm run build: Build the application
  • npm run test: Run tests
  • npm run lint: Run linter

Technology Stack

  • NestJS (Node.js framework)
  • TypeScript
  • Class-validator (Input validation)
  • UUID (Unique ID generation)
  • Express (HTTP server)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published