Overview
TheLibroService provides methods to create, read, update, and delete books in the Biblioteca Virtual system. It handles all HTTP communications with the backend /libros endpoint.
Location: src/app/core/services/libro.ts
Constructor
inject() function to obtain HttpClient instance.
Properties
string
default:"${environment.apiUrl}/libros"
Base URL for libro endpoints, configured from environment settings.
Methods
getAll()
Retrieves all books from the library.Observable<Libro[]> - Array of all books
array
GET ${apiUrl}
getById()
Retrieves a specific book by its ID.number
required
The unique identifier of the book to retrieve
Observable<Libro> - Single book object
Example:
GET ${apiUrl}/{id}
Use Case: Loading book data for editing forms
create()
Creates a new book in the library.object
required
Book data to create. Must include genero and autores.Required Properties:
titulo(string): Book titledisponible(boolean): Availability statusgenero(Genero): Genre object with id and nombreautores(Autor[]): Array of author objects
portada(string): Cover image URLanioPublicacion(number): Publication year
Observable<Libro> - The created book with server-assigned ID
Example:
POST ${apiUrl}
update()
Updates an existing book.number
required
The ID of the book to update
object
required
Updated book data. Should include all required fields (titulo, disponible, genero, autores)
Observable<Libro> - The updated book object
Example:
PUT ${apiUrl}/{id}
delete()
Deletes a book from the library.number
required
The ID of the book to delete
Observable<any> - Plain text response from server
Response Type: Text (uses responseType: 'text' to handle empty or plain text responses)
Example:
DELETE ${apiUrl}/{id}
Complete CRUD Example
Example component using all LibroService methods:Data Models
Libro Interface
Related Interfaces
Error Handling
All methods return Observables that may emit errors:See Also
- AutorService - Managing book authors
- GeneroService - Managing book genres
- PrestamoService - Managing book loans