Overview
TheApiClient class provides a type-safe Java interface for all backend API operations. It handles HTTP communication, JSON serialization, and authentication token management.
Location: src/main/java/com/borjaalmazan/entrega1_1/apiManager/ApiClient.java
Constructor
The base URL of the API server (e.g.,
https://api.example.com)Authentication Methods
login()
Authenticates a user and returns a JWT token.User’s email address
User’s password (plain text)
JWT token for authenticated requests. The method checks for
token, access_token, or jwt fields in the response.- Method: POST
- Endpoint:
/api/Auth/login - Content-Type:
application/json
IOException- If login fails (e.g., invalid credentials, network error)Exception- For other errors (JSON parsing, etc.)
User Methods
getMe()
Retrieves the current authenticated user’s profile.JWT authentication token from login()
User object containing profile information
- Method: GET
- Endpoint:
/api/users/me - Authorization: Bearer token
getNickName()
Retrieves a user’s nickname by their ID.The user ID
JWT authentication token
The user’s nickname. Handles both JSON and plain text responses.
- Method: GET
- Endpoint:
/api/users/{id}/nickname
Media Retrieval Methods
getAllMedia()
Retrieves all media files from the server.JWT authentication token
List of all media objects in the system
- Method: GET
- Endpoint:
/api/files/all
getMyMedia()
Retrieves media files uploaded by the current user.JWT authentication token
List of media objects owned by the authenticated user
- Method: GET
- Endpoint:
/api/files/me
getMediaByUser()
Retrieves media files uploaded by a specific user.The user ID to query
JWT authentication token
List of media objects uploaded by the specified user
- Method: GET
- Endpoint:
/api/files/user/{userId}
getMediaAddedSince()
Retrieves media files added after a specific timestamp.ISO-8601 timestamp (e.g.,
2025-11-18T12:00:00Z). Accepts either OffsetDateTime object or String.JWT authentication token
List of media objects added since the specified timestamp
- Method: GET
- Endpoint:
/api/files/added-since?from={timestamp}&container={container}
This method is used by the polling component to sync new media files periodically.
listBlobs()
Lists all blobs in the default container.JWT authentication token
Raw JSON response containing blob list
- Method: GET
- Endpoint:
/api/files?container=dimedianetblobs
Media Upload/Download Methods
download()
Downloads a media file by ID and saves it to disk.The media ID to download
Destination file path where the media will be saved
JWT authentication token
- Method: GET
- Endpoint:
/api/files/{id}?container=dimedianetblobs - Response: Binary stream
FileNotFoundException- If media with the specified ID is not found (404)IOException- For other download errors
uploadFileMultipart()
Uploads a file to the server using multipart/form-data encoding.The file to upload
Optional URL indicating where the file was originally downloaded from
JWT authentication token
Raw JSON response from server (typically contains uploaded media metadata)
- Method: POST
- Endpoint:
/api/files/upload - Content-Type:
multipart/form-data - Form Fields:
file- The binary file datadownloadedFromUrl- Optional source URLcontainer- Blob container name (dimedianetblobs)
Media Model
TheMedia class represents a media file in the system.
Location: src/main/java/com/borjaalmazan/entrega1_1/apiManager/Media.java
Unique media identifier
ID of the user who uploaded the media
Original source URL (if applicable)
Original filename of the uploaded media
MIME type (e.g.,
video/mp4, image/jpeg)Unique blob identifier in Azure Storage
Direct URL to access the blob
Configuration
Default Settings
- Connection timeout: 10 seconds
- Request timeout: 30 seconds
Custom HttpClient
The client is created with:Error Handling
All methods throwException. Common error patterns:
See Also
Authentication
JWT token management and user models
API Overview
High-level API architecture and flow

