Giter Site home page Giter Site logo

newsapi's Introduction

News API

A simple Node.js API for fetching news articles from the GNews API, with caching and Swagger documentation.

Table of Contents

Prerequisites

Before you begin, ensure you have met the following requirements:

  • Node.js and npm installed on your machine.
  • GNews API key. You can obtain one by signing up on the GNews website: GNews API.

Installation

  1. Clone this repository:

    git clone https://github.com/Ashishjagrawal/newsAPI.git
    cd newsAPI
  2. Install the project dependencies:

    npm install
  3. Create a .env file in the project root directory and set your GNews API key:

    GNEWS_API_KEY=your-api-key-here
    PORT=3000 

Usage

To start the server, run the following command:

npm start

Your API will be accessible at http://localhost:3000 (or your specified port).

API Endpoints

  • Fetch N news articles:

    • GET /api/news/:count
    • Example: http://localhost:3000/api/news/10
  • Get news articles by category:

    • GET /api/news/:category
    • Example: http://localhost:3000/api/news/business
  • Search for news articles by keywords:

    • GET /api/search
    • Example: http://localhost:3000/api/search?keyword=technology

For detailed information on each endpoint and their parameters, refer to the Swagger Documentation section.

Swagger Documentation

You can access the Swagger documentation for this API by visiting:

http://localhost:3000/api-docs

The Swagger UI provides an interactive interface for exploring and testing the API endpoints.

Environment Variables

  • GNEWS_API_KEY: Your GNews API key.
  • PORT (Optional): Specify the desired port for the server to run (default is 3000).

Contributing

Contributions are welcome! If you find a bug or have any suggestions, please open an issue or submit a pull request.

newsapi's People

Contributors

ashishjagrawal avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.