Skip to content

Seththaro/student-records-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Student Records API

A RESTful API for managing student records built with Node.js, Express, and MongoDB.

Overview

This application provides a backend system for managing student records through a RESTful API. It allows users to create, read, update, and delete student information using standard HTTP methods.

Features

  • CRUD Operations: Complete set of Create, Read, Update, and Delete operations for student records
  • RESTful API: Follows REST architectural style with standard HTTP methods
  • MongoDB Integration: Uses MongoDB Atlas for data persistence
  • Data Validation: Validates student data before saving to the database
  • Error Handling: Proper error handling with appropriate status codes

Technologies Used

  • Node.js: JavaScript runtime environment
  • Express.js: Web application framework for Node.js
  • MongoDB: NoSQL database
  • Mongoose: MongoDB object modeling tool
  • dotenv: Environment variables management

Project Structure

student-records-api/
├── controllers/         # Request handlers
│   └── studentController.js
├── models/             # Database models
│   └── Student.js
├── routes/             # API routes
│   └── studentRoutes.js
├── .env                # Environment variables (not included in repository)
├── .gitignore          # Git ignore file
├── dbConfig.js         # Database configuration
├── package.json        # Project dependencies
└── server.js           # Application entry point

API Endpoints

Method Endpoint Description Request Body Response
GET /students Retrieves all students - Array of student objects
GET /students/:id Retrieves a specific student - Student object
POST /students Creates a new student Student details (firstName, lastName, etc.) Created student object
PUT /students/:id Updates a student Updated student details Updated student object
DELETE /students/:id Deletes a student - Success message

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd student-records-api
    
  2. Install dependencies:

    npm install
    
  3. Create a .env file in the project root with the following variables:

    MONGODB_URI=your_mongodb_connection_string
    PORT=3000
    
  4. Start the server:

    npm run dev
    

API Usage Examples

Create a Student (POST)

POST http://localhost:3000/students
Content-Type: application/json

{
  "firstName": "John",
  "lastName": "Doe",
  "email": "john.doe@example.com",
  "course": "Computer Science"
}

Get All Students (GET)

GET http://localhost:3000/students

Get Student by ID (GET)

GET http://localhost:3000/students/60d21b4667d0d8992e610c85

Update Student (PUT)

PUT http://localhost:3000/students/60d21b4667d0d8992e610c85
Content-Type: application/json

{
  "firstName": "John",
  "lastName": "Smith",
  "email": "john.smith@example.com",
  "course": "Data Science"
}

Delete Student (DELETE)

DELETE http://localhost:3000/students/60d21b4667d0d8992e610c85

Development

To start the server in development mode with automatic restart on file changes:

npm run dev

To start the server in production mode:

npm start

Error Handling

The API returns appropriate HTTP status codes:

  • 200: Success
  • 201: Resource created
  • 400: Bad request
  • 404: Resource not found
  • 500: Server error

Future Enhancements

  • Authentication and authorization
  • Pagination for GET requests
  • Advanced filtering and sorting
  • Input sanitization
  • CORS configuration
  • Rate limiting

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors