DEV Community

Cover image for Fetch RSS Feed Using RSS to JSON API
Sohail Pathan
Sohail Pathan

Posted on

Fetch RSS Feed Using RSS to JSON API

Hi devs,

Let's quickly build a Node.js application that transforms RSS feeds into JSON format using the RSS to JSON API. This tutorial will guide you through setting up a simple server with Express, creating a user-friendly HTML form for submitting RSS feed URL.

Pre-requisite:

Step 1: Set Up Your Project

  • Create a new directory for your project and navigate into it:
   mkdir rss-fetcher
   cd rss-fetcher
Enter fullscreen mode Exit fullscreen mode
  • Initialize a new Node.js project by running:
   npm init -y
Enter fullscreen mode Exit fullscreen mode
  • Install required packages. You'll need express for creating the server and axios for making HTTP requests:
   npm install express axios
Enter fullscreen mode Exit fullscreen mode

Step 2: Create the Server and HTML Form

  • Create a file named server.js in your project directory.

  • Add the following code to server.js. This code sets up an Express server with a simple HTML form that allows users to input an RSS URL. It also includes a route to handle the form submission and fetch the RSS feed as JSON using the API.

   const express = require('express');
   const axios = require('axios');
   const app = express();
   const port = 3000;

   app.use(express.urlencoded({ extended: true })); // Middleware to parse form data

   app.get('/', (req, res) => {
     // HTML form for user input
     res.send(`
       <h2>RSS to JSON Converter</h2>
       <form action="/fetch-rss" method="post">
         <label for="rssUrl">RSS URL:</label><br>
         <input type="text" id="rssUrl" name="rssUrl" value=""><br><br>
         <input type="submit" value="Convert">
       </form> 
     `);
   });

   app.post('/fetch-rss', async (req, res) => {
     try {
       const response = await axios.post('https://api.apyhub.com/convert/rss-url/json?detailed=true', {
         url: req.body.rssUrl,
       }, {
         headers: {
           'Content-Type': 'application/json',
           'apy-token': 'YOUR_APY_TOKEN_HERE'
         }
       });
       res.json(response.data); // Send the converted JSON back to the client
     } catch (error) {
       res.status(500).send('Error fetching the RSS feed');
     }
   });

   app.listen(port, () => {
     console.log(`Server running at http://localhost:${port}`);
   });
Enter fullscreen mode Exit fullscreen mode

Replace 'YOUR_APY_TOKEN_HERE' with your actual API token.

Step 3: Run Your Application

  • Start your server by running:
   node server.js
Enter fullscreen mode Exit fullscreen mode
  • Open a web browser and navigate to http://localhost:3000. You'll see a form where you can enter the URL of an RSS feed.

  • Enter the RSS URL you want to convert and click "Convert". The server will send the URL to the RSS to JSON API, convert the feed to JSON, and display the JSON response in the browser.

That's it! This simple Node.js application allows users to convert RSS feeds to JSON format using a web form. You can extend this application by adding error handling, supporting more form fields for additional API parameters, or styling the form with CSS.

Top comments (1)

Collapse
 
ranjancse profile image
Ranjan Dailata • Edited

Question

  • Are you guys have a ready to use integration with platforms like

Pipedream
Zapier

  • How about building a workflow based automation as part of ApyHub platform?