Digital Library API
CMPS312 Assignment 4 • Qatar University
A comprehensive RESTful API for managing a digital library system with books, authors, members, staff, and transactions. Built with Next.js 15, PostgreSQL, and Prisma ORM.
🌐Base URL
Production API Endpoint
https://digital-library-api.vercel.app
📖How to Use cURL
cURL is a command-line tool for making HTTP requests. It comes pre-installed on macOS, Linux, and Windows 10+. Use it to test API endpoints directly from your terminal.
Basic Usage:
- •GET Request: Simply copy and paste the cURL command in your terminal
- •POST/PUT Requests: Include the
-dflag with JSON data - •Headers: Use
-Hto specify Content-Type and other headers
Quick Example:
# Open your terminal and run: curl -X GET https://digital-library-api.vercel.app/api/authors # You'll see JSON response with all authors!
💡 Tip: For better formatting, pipe the output through jq or use | python -m json.tool to pretty-print JSON responses.
🔐Authentication
/api/authAuthenticate staff member with username and password
Request Body:
{
"username": "admin",
"password": "admin123"
}Response (200 OK):
{
"staffId": "S001",
"username": "admin",
"fullName": "Admin User",
"role": "admin"
}💻cURL Example:
curl -X POST https://digital-library-api.vercel.app/api/auth \
-H "Content-Type: application/json" \
-d '{
"username": "admin",
"password": "admin123"
}'👤Authors Endpoints
/api/authorsGet all authors in the library
Response (200 OK):
[
{
"id": "auth001",
"name": "J.K. Rowling",
"biography": "British author...",
"birthYear": 1965
}
]💻 cURL Example:
curl -X GET https://digital-library-api.vercel.app/api/authors
/api/authors/:idGet a specific author by ID
Response (200 OK):
{
"id": "auth001",
"name": "J.K. Rowling",
"biography": "British author...",
"birthYear": 1965
}/api/authorsCreate a new author
Request Body:
{
"id": "auth008",
"name": "New Author",
"biography": "Biography text",
"birthYear": 1980
}Response (201 Created):
{
"id": "auth008",
"name": "New Author",
"biography": "Biography text",
"birthYear": 1980
}💻 cURL Example:
curl -X POST https://digital-library-api.vercel.app/api/authors \
-H "Content-Type: application/json" \
-d '{
"id": "auth008",
"name": "New Author",
"biography": "Biography text",
"birthYear": 1980
}'/api/authors/:idUpdate an existing author
Request Body:
{
"name": "Updated Name",
"biography": "Updated biography",
"birthYear": 1980
}/api/authors/:idDelete an author from the library
Response (200 OK):
{
"message": "Author deleted successfully"
}📚Books Endpoints
/api/booksGet all books (optional: filter by authorId)
Query Parameters (optional):
?authorId=auth001 // Filter by author
Response (200 OK):
[
{
"id": "book001",
"title": "Harry Potter and the Philosopher's Stone",
"authorId": "auth001",
"publishedYear": 1997,
"category": "Fantasy",
"isAvailable": true
}
]💻 cURL Example:
# Get all books curl -X GET https://digital-library-api.vercel.app/api/books # Get books by author curl -X GET "https://digital-library-api.vercel.app/api/books?authorId=auth001"
/api/books/:idGet a specific book by ID
Response (200 OK):
{
"id": "book001",
"title": "Harry Potter and the Philosopher's Stone",
"authorId": "auth001",
"publishedYear": 1997,
"category": "Fantasy",
"isAvailable": true
}/api/booksAdd a new book to the library
Request Body:
{
"id": "book009",
"title": "New Book",
"authorId": "auth001",
"publishedYear": 2024,
"category": "Fiction",
"isbn": "978-1234567890",
"pageCount": 350,
"publisher": "Publisher Name"
}Response (201 Created):
{
"id": "book009",
"title": "New Book",
"authorId": "auth001",
"publishedYear": 2024,
"category": "Fiction",
"isAvailable": true
}💻 cURL Example:
curl -X POST https://digital-library-api.vercel.app/api/books \
-H "Content-Type: application/json" \
-d '{
"id": "book009",
"title": "New Book",
"authorId": "auth001",
"publishedYear": 2024,
"category": "Fiction",
"isbn": "978-1234567890",
"pageCount": 350,
"publisher": "Publisher Name"
}'/api/books/:idUpdate book information
Request Body:
{
"title": "Updated Title",
"isAvailable": false
}/api/books/:idRemove a book from the library
Response (200 OK):
{
"message": "Book deleted successfully"
}👥Members Endpoints
/api/membersGet all library members
Response (200 OK):
[
{
"id": "M001",
"name": "Alice Johnson",
"email": "alice@example.com",
"phone": "+974-1234-5678",
"memberType": "student"
}
]💻 cURL Example:
curl -X GET https://digital-library-api.vercel.app/api/members
/api/members/:idGet a specific member by ID (includes transaction history)
Response (200 OK):
{
"id": "M001",
"name": "Alice Johnson",
"email": "alice@example.com",
"phone": "+974-1234-5678",
"memberType": "student",
"transactions": [...]
}/api/membersRegister a new library member
Request Body:
{
"id": "M007",
"name": "New Member",
"email": "newmember@example.com",
"phone": "+974-9999-9999",
"memberType": "student"
}Response (201 Created):
{
"id": "M007",
"name": "New Member",
"email": "newmember@example.com",
"phone": "+974-9999-9999",
"memberType": "student"
}💻 cURL Example:
curl -X POST https://digital-library-api.vercel.app/api/members \
-H "Content-Type: application/json" \
-d '{
"id": "M007",
"name": "New Member",
"email": "newmember@example.com",
"phone": "+974-9999-9999",
"memberType": "student"
}'/api/members/:idUpdate member information
Request Body:
{
"name": "Updated Name",
"email": "updated@example.com",
"memberType": "faculty"
}/api/members/:idRemove a member from the system
Response (200 OK):
{
"message": "Member deleted successfully"
}👔Staff Endpoints
/api/staffGet all staff members
Response (200 OK):
[
{
"staffId": "S001",
"username": "admin",
"fullName": "Admin User",
"role": "admin"
}
]💻 cURL Example:
curl -X GET https://digital-library-api.vercel.app/api/staff
/api/staff/:idGet a specific staff member by ID
Response (200 OK):
{
"staffId": "S001",
"username": "admin",
"fullName": "Admin User",
"role": "admin"
}/api/staffAdd a new staff member
Request Body:
{
"staffId": "S004",
"username": "newstaff",
"password": "password123",
"fullName": "New Staff",
"role": "staff"
}Response (201 Created):
{
"staffId": "S004",
"username": "newstaff",
"fullName": "New Staff",
"role": "staff"
}💻 cURL Example:
curl -X POST https://digital-library-api.vercel.app/api/staff \
-H "Content-Type: application/json" \
-d '{
"staffId": "S004",
"username": "newstaff",
"password": "password123",
"fullName": "New Staff",
"role": "staff"
}'/api/staff/:idUpdate staff member information
Request Body:
{
"username": "updatedusername",
"fullName": "Updated Name",
"role": "librarian"
}/api/staff/:idRemove a staff member
Response (200 OK):
{
"message": "Staff deleted successfully"
}🔄Transactions Endpoints
/api/transactionsGet all transactions (supports filtering by memberId or bookId)
Query Parameters (optional):
?memberId=M001 // Filter by member ?bookId=book001 // Filter by book
Response (200 OK):
[
{
"id": "T001",
"memberId": "M001",
"bookId": "book001",
"borrowDate": "2024-01-15T10:00:00Z",
"dueDate": "2024-02-15T10:00:00Z",
"isReturned": false
}
]💻 cURL Example:
# Get all transactions curl -X GET https://digital-library-api.vercel.app/api/transactions # Filter by member curl -X GET "https://digital-library-api.vercel.app/api/transactions?memberId=M001" # Filter by book curl -X GET "https://digital-library-api.vercel.app/api/transactions?bookId=book001"
/api/transactions/:idGet a specific transaction by ID
Response (200 OK):
{
"id": "T001",
"memberId": "M001",
"bookId": "book001",
"borrowDate": "2024-01-15T10:00:00Z",
"dueDate": "2024-02-15T10:00:00Z",
"returnDate": null,
"isReturned": false
}/api/transactionsCreate a new book borrowing transaction
Request Body:
{
"id": "T009",
"memberId": "M001",
"bookId": "book002",
"borrowDate": "2024-01-20T10:00:00Z",
"dueDate": "2024-02-20T10:00:00Z"
}Response (201 Created):
{
"id": "T009",
"memberId": "M001",
"bookId": "book002",
"borrowDate": "2024-01-20T10:00:00Z",
"dueDate": "2024-02-20T10:00:00Z",
"isReturned": false
}💻 cURL Example:
curl -X POST https://digital-library-api.vercel.app/api/transactions \
-H "Content-Type: application/json" \
-d '{
"id": "T009",
"memberId": "M001",
"bookId": "book002",
"borrowDate": "2024-01-20T10:00:00Z",
"dueDate": "2024-02-20T10:00:00Z"
}'/api/transactions/:idUpdate transaction (e.g., mark book as returned)
Request Body:
{
"isReturned": true,
"returnDate": "2024-02-10T15:30:00Z"
}/api/transactions/:idDelete a transaction record
Response (200 OK):
{
"message": "Transaction deleted successfully"
}⚠️Error Responses
Bad Request
{ "error": "Invalid request data" }Not Found
{ "error": "Resource not found" }Conflict
{ "error": "Resource already exists" }Internal Server Error
{ "error": "Failed to process request" }