### Complete Example: Searching, Getting Info, and Downloading Books Source: https://github.com/nicomua/flibusta-api/blob/master/README.md A comprehensive example demonstrating the workflow of searching for books, retrieving their detailed information, and then downloading a book in EPUB format. Includes basic error handling. ```typescript import { searchBooks, searchByAuthor, getBookInfo, downBook } from 'flibusta-api'; async function example() { try { // Search for books const books = await searchBooks('fantasy', 5); if (books.length > 0) { const book = books[0]; console.log(`Found: ${book.title} by ${book.author}`); // Get detailed info const info = await getBookInfo(book.id); if (info) { console.log(`Description: ${info.description}`); console.log(`Genres: ${info.genres.map(g => g.title).join(', ')}`); } // Download the book const file = await downBook(book.id.toString(), 'epub'); console.log(`Downloaded: ${file.fileName}`); } } catch (error) { console.error('Error:', error); } } example(); ``` -------------------------------- ### Install Flibusta API Source: https://github.com/nicomua/flibusta-api/blob/master/README.md Install the flibusta-api package using npm. This is the first step to using the library in your project. ```bash npm install flibusta-api ``` -------------------------------- ### Download Books and Get Download URLs with Flibusta API Source: https://github.com/nicomua/flibusta-api/blob/master/README.md Download a book in a specified format using downBook, or obtain its download URL using getUrl. Both functions require the book ID and an optional format. ```typescript import { downBook, getUrl } from 'flibusta-api'; // Download a book file const bookFile = await downBook('123456', 'epub'); console.log(bookFile.fileName); // Or just get the download URL const downloadUrl = getUrl('123456', 'mobi'); console.log(downloadUrl); ``` -------------------------------- ### Get Detailed Book Information with Flibusta API Source: https://github.com/nicomua/flibusta-api/blob/master/README.md Retrieve comprehensive details about a specific book using its ID with the getBookInfo function. This includes title, author, genres, and description. ```typescript import { getBookInfo } from 'flibusta-api'; // Get detailed information about a specific book const bookInfo = await getBookInfo(123456); console.log(bookInfo); // Returns: BookInfo | undefined ``` -------------------------------- ### Run Tests Source: https://github.com/nicomua/flibusta-api/blob/master/README.md Execute the project's test suite using the npm test command. This ensures that the library functions as expected and helps catch regressions. ```bash npm test ``` -------------------------------- ### Build Project Source: https://github.com/nicomua/flibusta-api/blob/master/README.md Build the project using the npm run build script. This command compiles the TypeScript code into JavaScript, preparing it for distribution or deployment. ```bash npm run build ``` -------------------------------- ### getUrl Source: https://github.com/nicomua/flibusta-api/blob/master/README.md Generates a download URL for a book in a specified format. Returns the URL as a string. ```APIDOC ## getUrl(id: string, format?: BookFormat): string ### Description Generate download URL for a book. ### Parameters #### Path Parameters - `id` (string) - Required - Book ID - `format` (BookFormat) - Optional - File format (default: 'mobi') ### Response #### Success Response (200) - `string` - The download URL for the book. ``` -------------------------------- ### Error Handling for Book Downloads Source: https://github.com/nicomua/flibusta-api/blob/master/README.md Demonstrates how to handle potential errors when downloading a book, specifically checking for 'unavailable' messages in the error response. This is crucial for robust application development. ```typescript import { downBook } from 'flibusta-api'; try { const file = await downBook('invalid-id', 'epub'); } catch (error) { if (error.message.includes('unavailable')) { console.log('Book is not available for download'); } else { console.error('Unexpected error:', error); } } ``` -------------------------------- ### Lint Code Source: https://github.com/nicomua/flibusta-api/blob/master/README.md Run the linter to check for code style and potential errors using the npm run lint command. This helps maintain code quality and consistency. ```bash npm run lint ``` -------------------------------- ### searchBooks Source: https://github.com/nicomua/flibusta-api/blob/master/README.md Searches for books by title or content. Returns a promise that resolves to an array of Book objects. ```APIDOC ## searchBooks(text: string, limit?: number): Promise ### Description Search for books by title or content. ### Parameters #### Path Parameters - `text` (string) - Required - Search query - `limit` (number) - Optional - Maximum number of results (default: 20) ### Response #### Success Response (200) - `Book[]` - An array of Book objects. ``` -------------------------------- ### downBook Source: https://github.com/nicomua/flibusta-api/blob/master/README.md Downloads a book file in a specified format. Returns a promise that resolves to a BookFile object. ```APIDOC ## downBook(id: string, format?: BookFormat): Promise ### Description Download a book file. ### Parameters #### Path Parameters - `id` (string) - Required - Book ID - `format` (BookFormat) - Optional - File format (default: 'mobi') ### Response #### Success Response (200) - `BookFile` - An object containing the book file and its details. ``` -------------------------------- ### Basic Book Search with Flibusta API Source: https://github.com/nicomua/flibusta-api/blob/master/README.md Search for books by title or content using the searchBooks function. Specify the search query and an optional limit for the number of results. ```typescript import { searchBooks } from 'flibusta-api'; // Search for books by title or content const books = await searchBooks('Harry Potter', 10); console.log(books); // Returns: Book[] ``` -------------------------------- ### getBookInfo Source: https://github.com/nicomua/flibusta-api/blob/master/README.md Retrieves detailed information about a specific book using its ID. Returns a promise that resolves to a BookInfo object or undefined. ```APIDOC ## getBookInfo(id: number): Promise ### Description Get detailed information about a specific book. ### Parameters #### Path Parameters - `id` (number) - Required - Book ID ### Response #### Success Response (200) - `BookInfo | undefined` - Detailed book information or undefined if not found. ``` -------------------------------- ### Search Books by Author with Flibusta API Source: https://github.com/nicomua/flibusta-api/blob/master/README.md Find books written by a specific author using the searchByAuthor function. Provide the author's name and an optional limit for the results. ```typescript import { searchByAuthor } from 'flibusta-api'; // Search for books by a specific author const books = await searchByAuthor('Tolkien', 5); console.log(books); // Returns: Book[] ``` -------------------------------- ### searchByAuthor Source: https://github.com/nicomua/flibusta-api/blob/master/README.md Searches for books by a specific author. Returns a promise that resolves to an array of Book objects. ```APIDOC ## searchByAuthor(text: string, limit?: number): Promise ### Description Search for books by author name. ### Parameters #### Path Parameters - `text` (string) - Required - Author name to search for - `limit` (number) - Optional - Maximum number of results (default: 10) ### Response #### Success Response (200) - `Book[]` - An array of Book objects. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.