An open API service indexing awesome lists of open source software.

https://github.com/gustavo-zamai/ucl-api-node-ts-express

UEFA Champions League REST API using Node.js, TypeScript, Express, Prisma, PostgreSQL and ZOD. A backend project focused on learning and practicing API development.
https://github.com/gustavo-zamai/ucl-api-node-ts-express

api backend expressjs nodejs postgresql prisma rest-api typescript zod

Last synced: 2 months ago
JSON representation

UEFA Champions League REST API using Node.js, TypeScript, Express, Prisma, PostgreSQL and ZOD. A backend project focused on learning and practicing API development.

Awesome Lists containing this project

README

          

# ๐Ÿ†๐Ÿ… UCL API - Node.js + TypeScript + Express

This is a RESTful API for retrieving data about football clubs and players participating in the UEFA Champions League. It was built using Node.js, TypeScript, and Express, and includes endpoints to access information such as club name, city, badge (logo), players, stats, and more.

## ๐Ÿ›  Technologies Used

- Node.js
- TypeScript
- Express
- CORS
- Prisma
- ZOD
- PostgreSQL

## ๐Ÿ“ Project Structure
```bash
ucl-api-node-ts-express/
โ”œโ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ controllers/
โ”‚ โ””โ”€โ”€ clubs-controller.ts
โ”‚ โ””โ”€โ”€ players-controller.ts
โ”‚ โ”œโ”€โ”€ models/
โ”‚ โ””โ”€โ”€ club-model.ts
โ”‚ โ””โ”€โ”€ http-status-code.ts
โ”‚ โ””โ”€โ”€ player-model.ts
โ”‚ โ””โ”€โ”€ statistics.ts
โ”‚ โ”œโ”€โ”€ repositories/
โ”‚ โ”œโ”€โ”€ clubs-repository.ts
โ”‚ โ”œโ”€โ”€ players-repository.ts
โ”‚ โ”œโ”€โ”€ routes/
โ”‚ โ””โ”€โ”€ routes.ts
โ”‚ โ”œโ”€โ”€ app.ts
โ”‚ โ””โ”€โ”€ server.ts
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ tsconfig.json
โ””โ”€โ”€ README.md
```

## ๐Ÿ“ฆ Installation

#### 1. Clone the repository:
```bash
git clone https://github.com/Gustavo-Zamai/ucl-api-node-ts-express.git
cd ucl-api-node-ts-express
```
#### 2. Install the dependencies:
```bash
npm install
```

#### 3. Start the development server:
```bash
npm run start:watch
```

#### 4. Open your browser at: `http://localhost:3000`

## ๐Ÿ” Available Endpoints
### Clubs
- `GET /clubs` โ€” Returns all clubs

- `GET /clubs/:id` โ€” Returns a specific club by id

- `GET /clubs/name/:name` โ€” Returns a specific club by name, or part

- `GET /clubs/league/:league` โ€” Returns the clubs linked to league

- `POST /clubs` โ€” Adds a new club

- `DELETE /clubs/:id` โ€” Deletes a club

### Players
- `GET /players` โ€” Returns all players

- `GET /players/:id` โ€” Returns a specific player by id

- `GET /players/name/:name` โ€” Returns a specific player by name, or part

- `GET /players/clubs/:club` โ€” Returns players by their club

- `GET /players/position/:position` โ€” Returns players by their position

- `GET /players/nationality/:nationality` โ€” Returns players by their nationality

- `POST /players` โ€” Adds a new player

- `PATCH /players/:id` โ€” Updates stats of an player

- `DELETE /players/:id` โ€” Deletes a player

## ๐Ÿ“Œ Club Object Example
```json
{
"id": "ca57a6ed-1ca4-429f-8519-2c189be2bba7",
"name": "Bayern Munich",
"badge": "https://upload.wikimedia.org/wikipedia/commons/1/1b/FC_Bayern_M%C3%BCnchen_logo_%282017%29.svg",
"foundation": 1900,
"city": "Munich",
"league": "Bundesliga"
}
```
## ๐Ÿ“Œ Player Object Example
```json
{
"id": "1ef0962d-951c-4e8a-9d03-f99981eec7f3",
"name": "Erling Haaland",
"club": "Manchester City",
"nationality": "NOR",
"position": "ST",
"statistics": {
"Pace": 89,
"Overall": 91,
"Passing": 65,
"Physical": 88,
"Shooting": 94,
"Defending": 45,
"Dribbling": 80
}
}
```
## ๐Ÿ›ก CORS Middleware
The project uses the cors middleware to allow cross-origin requests, which is essential for frontend integrations hosted on separate domains.

```ts
import cors from 'cors';
app.use(cors());
```

## ๐Ÿ”ฎ Future Improvements
#### ๐Ÿ” Authentication and Authorization with JWT

#### ๐Ÿ—„ Real Database Integration (PostgreSQL, MongoDB, or MySQL) โœ…

#### ๐ŸŒ Dynamic Filtering by nationality, league, or position โœ…

#### ๐Ÿ“Š Advanced Stats and Player Rankings

#### ๐Ÿงช Automated Testing using Jest and Supertest

#### ๐Ÿ“ฑ Cloud Deployment (Render, Vercel, Railway, etc.)

#### ๐Ÿ–ผ Dynamic Image Uploads for players and clubs -- In Progress

#### ๐Ÿณ Docker Support: -- In Progress

- Create a Dockerfile for the backend.

- Add docker-compose.yml to run with a real database.

- Make development setup and production deployment easier.

## ๐Ÿ“„ License
- This project is licensed under the MIT License.

## ๐Ÿ™‹โ€โ™‚๏ธ Author
#### Gustavo Zamai

[LinkedIn](https://www.linkedin.com/in/gustavo-sim%C3%A3o-zamai-664a5521a/) โ€ข
[GitHub](https://github.com/Gustavo-Zamai)