Skip to content

Commit

Permalink
Update book-api.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Guhapriya01 authored Oct 4, 2024
1 parent e9bd654 commit 80ba6ca
Showing 1 changed file with 142 additions and 21 deletions.
163 changes: 142 additions & 21 deletions api-docs/book-api.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,165 @@
# Library Management System API Documentation

<br/>

#### Base URL
### Base URL

```
http://localhost:8080/api
```

---

# Book API Endpoints

### Overview

The Book API provides a set of endpoints to manage the library's book collection. This includes functionalities to retrieve, add, update, and delete books. The API supports pagination, sorting, and detailed book information.

### 1. **Get All Books**

**Endpoint:** `/books`
**Method:** `GET`
**Description:** Retrieves a list of all books available in the library.
**Description:** Retrieves a paginated, sorted list of all books available in the library.

**Query Parameters:**

- `page` (Integer) : The page number of the result set (starting from 0). Default is `0`.
- `size` (Integer) : The number of books per page. Default is `5`.
- `sortBy` (String) : The field by which to sort the results (e.g., `title`, `author`, `publishedYear`). Default is `title`.
- `sortDir` (String) : The direction of sorting, either `asc` (ascending) or `desc` (descending). Default is `asc`.

**Example Requests:**

1. **Basic Request:**
```
GET /books
```
Retrieves the first 5 books sorted by `title` in ascending order.

2. **Pagination:**

Pagination allows the API to split the data into multiple pages. Use `page`
to specify the page number (starting from 0), and `size` to define how
many items are returned per page.

**Example:**

```
GET /books?page=0&size=7
```
Retrieves the first 7 books (on the first page).
```
GET /books?page=1&size=7
```

Retrieves the next 7 books (on the second page).

3. **Sorting:**

```
GET /books?sortBy=publishedYear&sortDir=desc
```

Retrieves books sorted by the `publishedYear` field in descending order.


```
GET /books?sortBy=author&sortDir=asc
```

Retrieves books sorted by the `author` field in ascending order.

**Fields supported for sorting books:**

- title ( default ) - `String`
- author - `String`
- isbn - `String`
- publisher - `String`
- genre - `String`
- copiesAvailable - `Integer`
- publishedYear - `Integer`

4. **Pagination + Sorting:**
```
GET /books?page=1&size=5&sortBy=author&sortDir=asc
```

Retrieves the second page with 5 books, sorted by `author` in ascending order.

**Success Response:**
- **Code:** `200 OK`
- **Content:**
```json
[
{
"bookId": 1,
"title": "Book Title",
"author": "Author Name",
"isbn": "123-4567891234",
"publisher": "Publisher Name",
"publishedYear": 2021,
"genre": "Genre Name",
"copiesAvailable": 5
}

]
{
"content": [
{
"bookId": 11,
"title": "Circe",
"author": "Madeline Miller",
"isbn": "978-0316388681",
"publisher": "Little, Brown and Company",
"publishedYear": 2018,
"genre": "Fantasy",
"copiesAvailable": 7
},
{
"bookId": 10,
"title": "Educated",
"author": "Tara Westover",
"isbn": "978-0399590504",
"publisher": "Random House",
"publishedYear": 2018,
"genre": "Memoir",
"copiesAvailable": 5
},
{
"bookId": 12,
"title": "The Night Circus",
"author": "Erin Morgenstern",
"isbn": "978-0385534635",
"publisher": "Doubleday",
"publishedYear": 2011,
"genre": "Fantasy",
"copiesAvailable": 2
}
],
"pageable": {
"pageNumber": 0,
"pageSize": 5,
"sort": {
"sorted": true,
"unsorted": false,
"empty": false
},
"offset": 0,
"paged": true,
"unpaged": false
},
"last": false,
"totalPages": 1,
"totalElements": 3,
"first": true,
"numberOfElements": 3,
"size": 5,
"number": 0,
"sort": {
"sorted": true,
"unsorted": false,
"empty": false
},
"empty": false
}
```

**Error Responses:**
None
**Error Responses:**
- **Code:** `400 BAD REQUEST`
- **Message:** `The specified 'sortBy' value is invalid.`
- **Content:**
```json
{
"timestamp": "2024-10-03T07:37:08.364+00:00",
"message": "The specified 'sortBy' value is invalid.",
"details": "/api/books"
}
```

<br/>

Expand Down Expand Up @@ -218,4 +339,4 @@ None
<br/>
<br/>
<br/>
<br/>
<br/>

0 comments on commit 80ba6ca

Please sign in to comment.