Overview
The .txt format provides a simple and straightforward way to handle lead data. Each line in the file represents a separate lead entry.
How to Create an API
POST /api/leads/txt
app.post('/api/leads/txt', (req, res) => {
const leads = getLeads(); // Function to fetch leads from your database
const txtOutput = leads.map(lead => `${lead.name}, ${lead.email}`).join('\n');
res.setHeader('Content-Type', 'text/plain');
res.attachment('leads.txt');
res.send(txtOutput);
});
Overview
The .xml format allows you to provide structured data, making it easier to parse for various applications.
How to Create an API
POST /api/leads/xml
app.post('/api/leads/xml', (req, res) => {
const leads = getLeads();
const xmlOutput = `${leads.map(lead => `${lead.name} ${lead.email} `).join('')} `;
res.setHeader('Content-Type', 'application/xml');
res.attachment('leads.xml');
res.send(xmlOutput);
});
Overview
The .xls format is used for Microsoft Excel and is suitable for users who prefer to work with spreadsheets.
How to Create an API
POST /api/leads/xls
xlsjs
to create the spreadsheet format.
const XLSX = require('xlsx');
app.post('/api/leads/xls', (req, res) => {
const leads = getLeads();
const ws = XLSX.utils.json_to_sheet(leads);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Leads');
const xlsOutput = XLSX.write(wb, { bookType: 'xls', type: 'buffer' });
res.setHeader('Content-Type', 'application/vnd.ms-excel');
res.attachment('leads.xls');
res.send(xlsOutput);
});
Overview
The .csv format is widely supported and is easy to import into various applications.
How to Create an API
POST /api/leads/csv
app.post('/api/leads/csv', (req, res) => {
const leads = getLeads();
const csvOutput = leads.map(lead => `${lead.name},${lead.email}`).join('\n');
res.setHeader('Content-Type', 'text/csv');
res.attachment('leads.csv');
res.send(csvOutput);
});
Overview
The .json format is highly versatile and widely used for API data transfer.
How to Create an API
POST /api/leads/json
app.post('/api/leads/json', (req, res) => {
const leads = getLeads();
res.setHeader('Content-Type', 'application/json');
res.json(leads);
});