To request data from the microservice, make a GET request to the /export endpoint with the email query parameter.
Example Request: curl "http://localhost:3000/export?email=nsitapara@gmail.com"
The microservice responds with a downloadable CSV file containing the requested data. The file is named expenses.csv.
Example Response Handling:
import axios from 'axios';
import fs from 'fs';
import path from 'path';
async function testExportEndpoint() {
const email = 'nsitapara@gmail.com';
const url = `http://localhost:3000/export?email=${encodeURIComponent(email)}`;
try {
const response = await axios.get(url, { responseType: 'blob' });
const filePath = path.resolve('downloaded_expenses.csv');
fs.writeFileSync(filePath, response.data);
console.log(`File saved to ${filePath}`);
} catch (error) {
console.error('Error calling export endpoint:', error.message);
}
}
testExportEndpoint();
- Client sends a GET request to
/exportwith theemailquery parameter. - Microservice fetches data from the Supabase API.
- Microservice converts the data to a CSV file.
- Microservice sends the CSV file as a response.
- Client receives and saves the CSV file.
-
Install Dependencies: npm install
-
Create and Configure the
.envFile: Create a.envfile in the root of your project. You will need to add the following variables:SUPABASE_API_URL: The URL of your Supabase API.SUPABASE_API_KEY: The API key of your Supabase API.SUPABASE_AUTH_TOKEN: The auth token of your Supabase API.
-
Start the Microservice: npx ts-node src/index.ts
-
Run the Test Script: npx ts-node src/test.ts
This README provides clear instructions for requesting and receiving data from the microservice, along with an example call and a UML sequence diagram.