Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Books API

A simple REST API for managing a list of books, built with Express and TypeScript.

Features

  • CRUD operations for books
  • In-memory storage
  • Input validation with Zod
  • Modular, class-based design
  • Repository pattern & simple dependency injection
  • RESTful error handling
  • Docker support (development, hot reload)
  • Jest tests for all endpoints

Setup

Local Development

  1. Install dependencies:
    npm install
  2. Start the server (hot reload):
    npm run dev
  3. Run tests:
    npm test

Docker (Development)

  1. Build the image:
    docker build -t books-api .
  2. Run the container:
    docker run -p 3000:3000 -v $(pwd):/app books-api

API Endpoints

Base URL: http://localhost:3000/api/books

Create a Book

  • POST /api/books
  • Body:
    {
      "title": "Book Title",
      "author": "Author Name",
      "publishedDate": "2023-01-01",
      "genre": "Fiction"
    }
  • Response:
    {
      "id": "...",
      "title": "Book Title",
      "author": "Author Name",
      "publishedDate": "2023-01-01",
      "genre": "Fiction"
    }

Get All Books

  • GET /api/books
  • Response:
    [
      {
        "id": "...",
        "title": "Book Title",
        "author": "Author Name",
        "publishedDate": "2023-01-01",
        "genre": "Fiction"
      }
    ]

Get Book by ID

  • GET /api/books/{id}
  • Response:
    {
      "id": "...",
      "title": "Book Title",
      "author": "Author Name",
      "publishedDate": "2023-01-01",
      "genre": "Fiction"
    }

Update a Book

  • PUT /api/books/{id}
  • Body: (any subset of fields except id)
    {
      "title": "New Title"
    }
  • Response:
    {
      "id": "...",
      "title": "New Title",
      "author": "Author Name",
      "publishedDate": "2023-01-01",
      "genre": "Fiction"
    }

Delete a Book

  • DELETE /api/books/{id}
  • Response: 204 No Content

Error Handling

  • Returns JSON error messages with appropriate HTTP status codes.

License

MIT

About

nodejs-book

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages