This project sets up an HTTP server using the Chi router in Go, providing various endpoints for handling user and feed data. It connects to a PostgreSQL database and uses middleware for authentication. The API allows users to manage feeds, follow them, and fetch posts from the feeds. It also includes an RSS scraper that periodically scrapes feeds and updates the database.
- Go programming language (version 1.16 or later)
- PostgreSQL
- Git (for cloning the repository)
- A .env file with the following variables
PORT=your_port_number
DB_URL=your_database_url
- main.go: Initializes the server, sets up routes, and configures the database connection.
- models.go: Defines the data models used in the application.
- rss.go: Contains the logic for processing and storing RSS feed data.
- scraper.go: Manages the periodic scraping of RSS feeds.
- json.go: Contains helper functions for JSON encoding and decoding.
- middleware_auth.go: Provides middleware for API key authentication.
- handler_readiness.go: Provides a health check endpoint.
- handler_err.go: Handles error simulation endpoints.
- handler_user.go: Manages user creation and retrieval endpoints.
- handler_feed.go: Handles feed creation and retrieval endpoints.
- handler_feed_follows.go: Manages endpoints for following and unfollowing feeds.
- Clone the repository:
git clone https://github.com/yourusername/rss-scraper.git
- Navigate to the project directory:
cd rss-scraper
- Install dependencies
go mod tidy
- Build the project:
go build
- Run the application:
./rss-scraper
The server will start running on the specified port (e.g., http://localhost:8080).
When authentication is required, users must add an Authorization header with the value ApiKey {your_api_key_here}
.
- Description: Checks the readiness of the server.
- Response: 200 OK
- Description: Triggers an error for testing purposes.
- Response: 500 Internal Server Error
- Description: Creates a new user.
- Request Body: JSON object containing user data.
{
"name": "{name}"
}
- Response: 201 Created
- Description: Retrieves the current user.
- Authentication: Required.
- Response: 200 OK with user data.
- Description: Creates a new feed.
- Request Body: JSON object containing feed data.
{
"name": "{feed name}",
"url": "{feed URL}"
}
- Authentication: Required.
- Response: 201 Created
- Description: Retrieves all feeds.
- Response: 200 OK with a list of feeds.
- Description: Retrieves posts for the current user.
- Authentication: Required.
- Response: 200 OK with a list of posts.
- Description: Follows a feed.
- Request Body: JSON object containing feed follow data.
{
"feed_id": "{feed id}"
}
- Authentication: Required.
- Response: 201 Created
- Description: Retrieves the feeds that the current user follows.
- Authentication: Required.
- Response: 200 OK with a list of followed feeds.
- Description: Unfollows a feed.
- URL Parameter: feedFollowID - ID of the feed follow to delete.
- Authentication: Required.
- Response: 204 No Content
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.