This repository contains a web application developed as part of the "Databases and API" course at Oulu University of Applied Sciences. The application is built using Node.js with Express.js framework and MySQL database, providing web interfaces to manage books and student records.
- Node.js
- Express.js
- MySQL
- dotenv for environment variables management
- Additional middleware such as cookie-parser, debug, and morgan for logging and debugging
app.js
- Initializes the app and sets up middleware and routes.database.js
- Databaseindex.js
- Index/models
- Contains models for database operations.book_model.js
- Handles CRUD operations for books.student_model.js
- Handles CRUD operations for students.
/bin
- Express.js dirwww
- Express.js web-server settings.
/routes
- Defines the router for handling requests.index.js
- Root router.book.js
- Router for book-related operations.student.js
- Router for student-related operations.
To get this project up and running, follow these steps:
- Clone the repository:
git clone https://github.com/vem882/DB-API.git
- Install dependencies:
npm install
- Configure your MySQL database settings in an
.env
file based on the.env.example
provided in the repository. - Start the application:
npm start
The application exposes several endpoints for interacting with the database:
GET /book
- Retrieves all books.GET /book/:id
- Retrieves a book by its ID.POST /book
- Adds a new book. Requiresname
,author
, andisbn
.DELETE /book/:id
- Deletes a book by its ID.PUT /book/:id
- Updates an existing book. Requiresname
,author
, andisbn
.
GET /student
- Retrieves all students.GET /student/:id
- Retrieves a student by ID.POST /student
- Adds a new student. Requires data specific to your project needs.DELETE /student/:id
- Deletes a student by ID.PUT /student/:id
- Updates an existing student. Requires data specific to your project needs.