/api-basics

Reddit API basics

Primary LanguageJavaScript

Reddit API Search App

A simple React application using Vite that allows users to search for subreddits and fetch posts from Reddit's API. Users can choose between Axios or Superagent to make API calls.

Features

  • Search for any subreddit
  • Fetch data from Reddit API
  • Display a list of posts with clickable links
  • Option to use either Axios or Superagent for API requests

Built With

  • React - A JavaScript library for building user interfaces
  • Vite - Next Generation Frontend Tooling
  • Axios - Promise-based HTTP client for the browser and Node.js
  • Superagent - Small progressive client-side HTTP request library
  • Reddit API - Official API provided by Reddit for fetching subreddit data

Getting Started

Prerequisites

Make sure you have Node.js installed on your machine.

Installation

  1. Clone the repository:

    git clone https://github.com/Sagnik-Coder24/api-basics.git
    cd api-basics
    
  2. Install dependencies:

    npm install

Usage

  1. Start the development server:

    npm run dev
    
  2. Open your browser and navigate to http://localhost:5173.

  3. Use the search input to enter a subreddit name and fetch posts.

Switching between Axios and Superagent

In the app's settings, you can toggle between using Axios and Superagent for making API calls. This will allow you to see how each library handles requests and responses.

API Reference

The application fetches data from the following endpoint:

Replace {subreddit} with the name of the subreddit you want to search.

Example Usage

  1. Enter a subreddit name (e.g., reactjs) in the search input.
  2. Click the search button to fetch posts.
  3. A list of posts will be displayed, each linking to the respective Reddit post page.

Contributing

Feel free to submit issues or pull requests. Contributions are welcome!

Acknowledgments

  • Reddit API - For providing the data
  • React - For making UI development simple and efficient
  • Vite - For the modern build tool