A NestJS REST API for managing Discogs music collections and wantlists with CRUD operations, advanced sorting, pagination, and API key authentication.
- Collection Management: Add, remove, and organize Discogs collection items with ratings and notes
- Wantlist Management: Track desired releases with personal notes
- Advanced Sorting: Sort by date added, title, artist, year, rating, genre, or format
- Pagination: Handle large collections with configurable page sizes
- Statistics: Collection and wantlist analytics with rating averages
- API Key Authentication: Secure endpoints with token-based access control
- Request Validation: Comprehensive input validation with detailed error messages
- API Documentation: Interactive Swagger/OpenAPI documentation
- Framework: NestJS 10.x
- Database: PostgreSQL with TypeORM
- Validation: class-validator, class-transformer
- Documentation: Swagger/OpenAPI
- Language: TypeScript
- Node.js 18+
- PostgreSQL 13+
- npm or yarn
-
Clone repository
git clone https://github.com/caleb-vanlue/discogs-api.git cd discogs-api -
Install dependencies
npm install
-
Configure environment
cp .env.example .env
Required environment variables:
# API Security API_KEY=your-generated-api-key # Database DB_HOST=localhost DB_PORT=5432 DB_USERNAME=postgres DB_PASSWORD=your_password DB_NAME=discogs # Discogs Integration DISCOGS_USERNAME=your_discogs_username DISCOGS_API_TOKEN=your_discogs_token # Application PORT=3000 NODE_ENV=development
-
Database setup
createdb discogs npm run migration:run
-
Start application
# Development npm run start:dev # Production npm run build npm run start:prod
http://localhost:3000
All endpoints require API key authentication via one of:
- Header:
X-API-Key: your-api-key - Header:
Authorization: Bearer your-api-key
Access Swagger UI at http://localhost:3000/api for complete API documentation with request/response examples.
GET /collection/{userId}- Retrieve user collection with sorting and paginationPOST /collection/{userId}/collection- Add release to collectionDELETE /collection/{userId}/collection/{releaseId}- Remove from collectionGET /collection/{userId}/stats- Collection statistics
GET /collection/{userId}/wantlist- Retrieve user wantlistPOST /collection/{userId}/wantlist- Add release to wantlistDELETE /collection/{userId}/wantlist/{releaseId}- Remove from wantlist
GET /releases- Browse all releases with sorting and paginationGET /releases/{discogsId}- Get specific release by Discogs ID
Pagination
limit: Items per page (1-100, default: 50)offset: Items to skip (default: 0)
Sorting
sort_by: Field to sort by- Collections:
dateAdded,title,primaryArtist,year,rating,primaryGenre,primaryFormat - Wantlists:
dateAdded,title,primaryArtist,year,primaryGenre,primaryFormat
- Collections:
sort_order:ASCorDESC(default:DESC)
Get collection with sorting
curl -H "X-API-Key: your-key" \
"http://localhost:3000/collection/username?limit=25&sort_by=title&sort_order=ASC"Add to collection
curl -X POST -H "X-API-Key: your-key" -H "Content-Type: application/json" \
-d '{"releaseId": 123456, "rating": 5, "notes": "Signed copy"}' \
"http://localhost:3000/collection/username/collection"Create migration
npm run migration:generate -- --name=MigrationNameRun migrations
npm run migration:runRevert migration
npm run migration:revert- Use separate
.envfiles for different environments - Validate configuration for each deployment target
- Ensure API keys are securely managed in production