Welcome to the CSV Assignment API documentation. This API allows you to import CSV files, check their processing status, and retrieve the processed output. A working demo is available at https://csv.nekoflix.live.
For better documentation please visit the dev server or working demo.
The API provides the following endpoints:
- POST /csv/import: Import a CSV file for processing.
- GET /csv/{id}/status: Retrieve the processing status of a CSV file.
- GET /csv/{id}/output: Get the processed CSV output.
To set up the CSV Assignment API locally, follow these steps:
- Node.js: Ensure you have Node.js installed. You can download it from nodejs.org.
- Database: Set up a database (e.g., PostgreSQL and Redis) and configure it in the
.env
file from reference of.env.example
.
-
Clone the Repository:
git clone https://github.com/sayeed205/csv-assignment cd csv-assignment
-
Install Dependencies:
npm install
-
Environment Configuration:
- Copy the
.env.example
file to.env
and update the necessary environment variables, especially the database configuration.
- Copy the
-
Run Migrations:
node ace migration:run
-
Start the Server:
npm run dev
-
Access the API:
- The API will be available at
http://localhost:{PORT}
.
- The API will be available at
- You can use tools like Postman, curl or visit the api to test the API endpoints locally.
- Summary: Import a CSV file.
- Description: This endpoint allows you to upload a CSV file for processing. Optionally, you can provide a webhook URL to be notified upon completion.
- Request Body:
- file: (required) The CSV file to be uploaded. Must be in
multipart/form-data
format. - webhookUrl: (optional) A URL to be notified when processing is complete.
- file: (required) The CSV file to be uploaded. Must be in
- Responses:
- 201 Created: CSV imported successfully.
- 422 Unprocessable Entity: Validation failed, e.g., invalid CSV format or columns.
- Summary: Retrieve CSV processing status.
- Description: Check the current status of a CSV file processing.
- Path Parameters:
- id: (required) The UUID of the CSV file.
- Responses:
- 200 OK: Returns the status and any errors encountered during processing.
- 404 Not Found: CSV file not found.
- Summary: Get processed CSV output.
- Description: Retrieve the processed CSV file.
- Path Parameters:
- id: (required) The UUID of the CSV file.
- Responses:
- 200 OK: Returns the processed CSV file.
- 404 Not Found: CSV file not found.
The CSV Assignment API supports webhook integration to notify external services when a CSV file has been processed. This feature is useful for automating workflows and integrating with other systems.
- When you import a CSV file using the POST /csv/import endpoint, you can optionally provide a
webhookUrl
in the request body. - Once the CSV processing is complete, the API will send a POST request to the specified
webhookUrl
. - The webhook payload includes the status of the CSV processing, the time it was processed, and any errors encountered.
The POST request to the webhook URL will include the following JSON payload:
{
"status": "completed",
"processedAt": "2023-10-01T12:00:00Z",
"error": null
}
- status: The current status of the CSV processing (e.g.,"pending", "processing", "completed", "error").
- processedAt: The timestamp when the CSV processing was completed.
- error: Any error message encountered during processing, or
null
if there were no errors.
To configure a webhook:
-
When importing a CSV file, include the
webhookUrl
parameter in your request:curl -X POST 'http://localhost:3333/csv/import' \ -F 'file=@/path/to/your/file.csv' \ -F 'webhookUrl=https://your-webhook-url.com'
-
Ensure that the specified
webhookUrl
is accessible and can handle POST requests with JSON payloads.
- If the webhook invocation fails, the error will be logged, but it will not affect the processing of the CSV file.
- Ensure your webhook endpoint is reliable and can handle potential retries or failures.
curl -X POST 'http://localhost:3333/csv/import' \
-F 'file=@/path/to/your/file.csv' \
-F 'webhookUrl=https://your-webhook-url.com'
curl -X GET 'http://localhost:3333/csv/{id}/status'
curl -X GET 'http://localhost:3333/csv/{id}/output'
For a live demonstration, visit https://csv.nekoflix.live.