This is my approach to creating a REST API that allows users to submit any URL for an RSS feed. It parses the URL to extract links for all articles within it and returns a list of article titles and descriptions in JSON format. The endpoint is protected using JWT authentication.
- Clone the repo:
git clone [repository-url]
- Install the required packages:
pip install -r requirements.txt
- Set up Firebase Admin SDK by placing your firebase-sdk.json file in the project directory using Firebase Console:
- Go to the Firebase Console.
- Create a new project.
- Go to Project settings > Service accounts.
- Click "Generate new private key" and save the file
Start the Flask application:
python app.py
The server will start on http://localhost:5000.
You can test the application using a tool like Postman or a browser for GET requests. I used postman, screenshots are given below.
- Set Request URL and Method:
- In Postman, set the request method to POST. Enter the URL of your endpoint, e.g., http://127.0.0.1:5000/parse-rss.
- Add Authorization:
- Go to the "Authorization" tab. Select "Bearer Token" from the Type dropdown. Paste your JWT token into the "Token" field.
- Token is generated by running firebase_token_gen.html
- Set Request Body:
- Go to the "Body" tab. Select "raw" and choose "JSON" from the dropdown. Enter the request url. For example:
{
"url": "http://www.theguardian.com/world/usa/rss"
}
Example Urls to test the API:
- "http://www.theguardian.com/world/usa/rss"
- "http://www.cbsnews.com/latest/rss/main"
- "http://www.npr.org/rss/rss.php?id=1003"
- "http://www.npr.org/rss/rss.php?id=1128"
- "http://globalnews.ca/politics/feed/"
- Description: Parses the RSS feed from the given URL.
- Headers: Authorization: Bearer [JWT Token]
- Body:
{
"url": "[RSS Feed URL]"
}
- Description: Displays the contents of the parsed RSS feeds.
The SQLite database consists of two tables:
- RSSFeed: Stores the RSS feed URLs and the last parsed time.
- Article: Stores the articles' titles and descriptions, linked to their respective RSS feeds.