feat: Add /process/preview endpoint for CSV previews #7
+70
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #3
This pull request introduces a new lightweight endpoint,
POST /process/preview
, designed to generate a quick preview of a CSV/Excel file. This feature allows a frontend application to quickly display column names and the first few rows of data after a user provides a file, URL, or raw text, enhancing the user experience for data import workflows.Implementation Details
POST /process/preview
route inapp/process.py
./process/csv
endpoint (file
upload,url
, orraw_csv
) for consistency.400
status code, matching the existing API's error response format.generate_preview()
function toapp/processing.py
.parse_input()
logic to handle any data source and create a pandas DataFrame.df.head(5)
).{"columns": [...], "rows": [...]}
.All acceptance criteria outlined in the issue have been met.
Testing and Validation
I have successfully tested the endpoint locally. I used a
curl
command for the final verification because I encountered a422 Unprocessable Entity
error when using the interactive API docs at/docs
.It appears the docs page sends placeholder strings for the optional
file
andurl
parameters, which causes the backend validation to fail. Thecurl
command allowed me to construct the request correctly by sending only the intended parameter (file
orraw_csv
).Here is the screenshot from the successful
curl
test in my terminal:How to Test
This endpoint can be tested by sending a sample CSV file using
curl
.Note: Testing via the interactive docs at
/docs
is currently unreliable due to an issue where the UI sends extra empty parameters, causing a422
validation error. Thecurl
method below is the recommended way to verify the functionality.Create a sample data file: In the project's root directory, create a new file named
data.csv
with the following content:Run the server locally:
Execute the
curl
command: In a new terminal window, run the following command to upload thedata.csv
file to thefile
parameter:Verify the response: Confirm that the server responds with a
200 OK
status and the correctly formatted JSON preview, including the column names and the first five rows of data.