Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We need a Rest API for our library. Our mission is to implement a Rest API for the library which satisfies the below requirements: 1.

We need a Rest API for our library. Our mission is to implement a Rest API for the library which satisfies the below requirements:

1. You are going to use ExpressJs and start the server on port 8889

2. The entities are Books and Users. (Note you may need to have extra parameters to handle borrowing operations)

a. User { username: a unique string that is going to be used in the API URLs to specify the user in Rest API phone: it is a mandatory string that should follow this format: 123-456-7890 }

b. Book { id: a unique number that should get generated automatically (start from 1) and returned by the API in the case of creating a new book.

title: a unique mandatory string inventory_count: the number of copies of this book available in our library inventory. If this number is 0 we cannot loan it to anybody because we dont have any copy to loan.

}

3. The restful API should implement the CRUD methods for each entity.

a. URL for users: localhost:8889/user/:user_name/

b. URL for books: localhost:8889/book/:id/

4. The restful API data should reside in MongoDB.

5. Your app should contain a variable named mongodb_url at the first line, so I can change it and test your codes with my own MongoDB server. (this is important because I cannot test your code without it, and your score will be 0. You can check our previous sessions recorded video if you dont know what I mean here)

6. We are going to use this API for the functionalities like borrowing a book and returning a book

a. Url for borrowing a book: localhost:8889/user/:user_name/borrows/:id

i. This function should check the requirements before performing the task:

1. Is the book available in the library?

2. Does the user have the capacity to borrow another book? (the upper limit of the borrowed books for each person is 3(inclusive))

ii. Should update the relevant attributes in DB (you should figure out which attributes and how)

iii. As you guessed, it is a POST method. b. Url for returning a book: localhost:8889/user/:user_name/returns/:id

i. Should update the relevant attributes in DB (you should figure out which attributes and how)

ii. As you guessed, it is a POST method.

c. Url to list borrowed books: localhost:8889/user/:user_name/borrowed

i. It is a GET method.

ii. The response lists all the borrowed books' names by the specified user.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Management Accounting Information for Decision-Making and Strategy Execution

Authors: Anthony A. Atkinson, Robert S. Kaplan, Ella Mae Matsumura, S. Mark Young

6th Edition

137024975, 978-0137024971

Students also viewed these Programming questions

Question

=+a) What is the minimax choice?

Answered: 1 week ago

Question

40. Consider a M/G/1 system with E[S] Answered: 1 week ago

Answered: 1 week ago