# red head API Server A Python Flask server that serves data for the red head application. ## Endpoints - `GET /posts` - Get first 10 posts for initial load - `GET /posts/more?count=N` - Get next 10 posts, starting from index N - `GET /posts/total` - Get total number of posts available - `GET /` - Server status endpoint ## Setup Instructions 1. Install Python 3 if you don't have it already 2. Navigate to the server directory: ```bash cd /Users/jariancottingham/Projects/redhead/src/server ``` 3. Create a virtual environment (recommended): ```bash python -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate ``` 4. Install dependencies: ```bash pip install -r requirements.txt ``` 5. Run the server: ```bash python app.py ``` 6. The server will be available at http://localhost:5000 ## Data Format The server returns JSON data in the same format as used by the frontend: ```json [ { "id": "1", "title": "This is a sample Reddit post title", "url": "https://example.com/sample-post", "image": "https://picsum.photos/400/300?random=1" } ] ``` ## Usage with Frontend Update the frontend's `fetchRedditPosts()` and `fetchMorePosts()` functions to call your server endpoints instead of using mock data: ```javascript // Replace URLs with your server endpoints function fetchRedditPosts() { return fetch('/posts') .then(response => response.json()) } function fetchMorePosts(currentCount) { return fetch(`/posts/more?count=${currentCount}`) .then(response => response.json()) } ``` ## Example Data The sample data is stored in `sample_posts.json`. You can replace this with your own data, or connect to a real Reddit API. To add your own posts: 1. Replace the content of `sample_posts.json` with your data 2. Each post should follow this structure: ```json { "id": "post_id", "title": "Post title", "url": "https://example.com/post-url", "image": "https://example.com/image-url" } ``` ## Running the Server After installation, run the server with: ```bash python app.py ``` The server will start on port 5000 and listen for connections from localhost. ## Testing Endpoints You can test the endpoints directly using curl or a browser: - `http://localhost:5000/posts` - Get initial posts - `http://localhost:5000/posts/more?count=10` - Get more posts starting from index 10 - `http://localhost:5000/posts/total` - Get total post count