Skip to content

A simple microservice that takes a users email, searches a db for the emails expense information, and returns a csv with the db information.

License

Notifications You must be signed in to change notification settings

nsitapara/export-to-csv

Repository files navigation

Export to CSV Microservice

Communication Contract

Requesting Data

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"

Receiving Data

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();

UML Sequence Diagram

UML Sequence Diagram

  1. Client sends a GET request to /export with the email query parameter.
  2. Microservice fetches data from the Supabase API.
  3. Microservice converts the data to a CSV file.
  4. Microservice sends the CSV file as a response.
  5. Client receives and saves the CSV file.

Running the Microservice

  1. Install Dependencies: npm install

  2. Create and Configure the .env File: Create a .env file 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.
  3. Start the Microservice: npx ts-node src/index.ts

  4. 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.

About

A simple microservice that takes a users email, searches a db for the emails expense information, and returns a csv with the db information.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •