REST API URL Structure Suggestion

Viewed 98

I have 2 tables, MEMBERS and BOOKS in my SQL. So I want to let members ISSUE, RENEW and RETURN books. So all are PATCH request which updates a specific row in the table BOOK. But to do that I will have to include verb in the URL (ISSUE, RENEW or RETURN). Is this a good url structure ? If bad, how should I approach this. database schema

Here the constraints is 1 book only has one copy and a book has 1 author only

UPDATE: I changed my database schema now and moved some properties now to a different table called Transactions. Now can I use POST(issue book/add row in Transaction), PATCH(renew book/edit the due date of the transaction) and DELETE(return book/remove the row from Transaction). Base URL remains same for all. Only methods change.

Base URL:/api/members/{id}/books/{id}/ enter image description here

2 Answers

Formally speaking, an issue, a return, and renewal are called "verbal noun", so it is fine. In any case, this API structure sounds fine.

If I were you I would check if maybe POST method is more appropriate for these kinds of operations.

you should try something like below using PathVariable.

path:-- /v1/members/{id}

RequestBody:--

{
               member name="XXX", or email
                bookname="XXXX",
                status="issue/return/renew"
                 }

then you should valid Id and member name or ( id and email).

if(Success)
 read request and perform a/c that 
else
  throw member not found.
Related