Simple REST API built using Node.js, Express, and TypeScript allows CRUD operations on data stored transiently on the server.
- Clone the repository to your local machine.
- Run
npm install
to install dependencies. - Create a
.env
file in the root directory and populate the required environment variables. - Run
npm run build
to compile the TypeScript code into JavaScript. The compiled code will be in thedist
directory. - Run
npm start
to start the server.
With the server active you can run node test-api.js in a separate terminal for simople testing, or use an APOI client of your choice.
/v1/books
: Retrieve all books with available copies. (GET)/v1/books/:bookId
: Retrieve details about a specific book. (GET)/v1/books/:bookId/rent
: Rent a book (userId in request body). (POST)
/v1/users/:userId/books
: Retrieve a user's rented books. (GET)/v1/rentals/:rentalId/return
: Return a rented book. (POST)
The POST operation /v1/books/:bookId/rent
required this parameter in the request body:
userID
: The ID of the User.
Your .env
file should include the following variables:
PORT
: The target Localhost port.
. | .env | notes.txt | package-lock.json | package.json | README.md | test-api.js | tsconfig.json | app.js | +---controllers | bookController.js | rentalController.js | userController.js | +---data | seedData.js | storage.js | +---models | Book.js | Rental.js | User.js | ---services bookService.js rentalService.js userService.js