Welcome to the Score API! This project provides a robust backend for managing scores in a game, built using Node.js, Express, TypeScript, and Prisma. It also includes various middleware for security, validation, and logging.
- CRUD Operations: Create, Read, Update, and Delete scores.
- Validation: Input validation using Joi.
- Error Handling: Centralized error handling.
- Logging: Request logging using Morgan and Winston.
- Security: Secure HTTP headers with Helmet.
- CORS: Cross-Origin Resource Sharing enabled.
- API Documentation: Swagger UI for API documentation.
- Node.js: JavaScript runtime.
- Express: Web framework for Node.js.
- TypeScript: Typed JavaScript for safer and more robust code.
- Prisma: ORM for database management.
- Cors: Middleware for enabling CORS.
- Joi: Schema validation library.
- Helmet: Helps secure Express apps by setting various HTTP headers.
- Morgan: HTTP request logger middleware.
- Winston: Logging library.
- Swagger-UI-Express: Middleware to serve auto-generated Swagger API docs.
To get started with the project, follow these steps:
-
Clone the repository:
```sh git clone https://github.com/AleksandrSherehkov/snake-backend.git ```
-
Navigate to the project directory:
```sh cd score-api ```
-
Install the dependencies:
```sh npm install ```
-
Set up your
.env
file with your database connection string:```env DATABASE_URL="your-database-url" ```
-
Run Prisma migrations to set up your database:
```sh npx prisma migrate dev ```
-
Start the server:
```sh npm run dev ```
- URL:
/api/scores
- Method:
POST
- Request Body: ```json { "name": "string", "score": "integer" } ```
- Responses:
201
: Score successfully created or updated.400
: Invalid input.
- URL:
/api/scores
- Method:
GET
- Responses:
200
: List of top 10 scores.
- URL:
/api/check-unique-name
- Method:
POST
- Request Body: ```json { "name": "string" } ```
- Responses:
200
: Returns if the name is unique.400
: Invalid input.
Contributions are welcome! Please fork this repository and submit a pull request.
This project is licensed under the MIT License.
For any inquiries, please reach out to me at aleksandr.shereshkov@gmail.com.
Enjoy using the Score API! 🏆