Here's an example of a Spring Boot Controller that accepts a request payload of type EmployeeRequest
, generates a CSV file based on the input data, compresses the file into a ZIP, and returns the zipped file as a response:
Spring Boot Controller
Supporting Classes
EmployeeRequest
This class represents the input request payload that contains a list of employees.
Employee
This class represents the individual employee data.
How It Works
- Input: The API receives a JSON payload containing a list of employees with their details (
firstName
, lastName
, middleName
, and dateOfBirth
). - CSV Generation: It generates a CSV file with these details in memory.
- ZIP Compression: The CSV file is compressed into a ZIP archive.
- Response: The ZIP file is returned to the client with appropriate headers for file download.
Example Request
POST Request
Request Body
Response
The API returns a employees.zip
file containing the CSV file. The CSV will look like this: