Overview
TheAutorService provides methods to create, read, update, and delete authors in the Biblioteca Virtual system. It handles all HTTP communications with the backend /autores endpoint.
Location: src/app/core/services/autor.ts
Constructor
inject() function to obtain HttpClient instance.
Properties
string
default:"${environment.apiUrl}/autores"
Base URL for autor endpoints, configured from environment settings.
Methods
getAll()
Retrieves all authors from the database.Observable<Autor[]> - Array of all authors
array
GET ${apiUrl}
getById()
Retrieves a specific author by their ID.number
required
The unique identifier of the author to retrieve
Observable<Autor> - Single author object
Example:
GET ${apiUrl}/{id}
Use Case: Loading author data for editing forms
create()
Creates a new author in the database.Autor
required
Author data to createRequired Properties:
nombre(string): Author’s full name
urlFoto(string): URL to author’s photoid(number): Should be omitted for new authors (server assigns)
Observable<Autor> - The created author with server-assigned ID
Example:
POST ${apiUrl}
update()
Updates an existing author.number
required
The ID of the author to update
Autor
required
Updated author dataProperties:
id(number): Author ID (should match path parameter)nombre(string): Updated author nameurlFoto(string, optional): Updated photo URL
Observable<Autor> - The updated author object
Example:
PUT ${apiUrl}/{id}
delete()
Deletes an author from the database.number
required
The ID of the author to delete
Observable<any> - Plain text response from server
Response Type: Text (uses responseType: 'text' to accept string responses from backend)
Example:
DELETE ${apiUrl}/{id}
Note: Deletion may fail if the author has associated books. Handle this error appropriately in your UI.
Complete CRUD Example
Example component using all AutorService methods:Form Example
Example form component for creating/editing authors:Data Model
Autor Interface
Error Handling
Common error scenarios and how to handle them:See Also
- LibroService - Managing books with authors
- GeneroService - Managing book genres
- Autor Model - Author data structure