NEWS API

Overview

Project instructions

Create a simple API that interacts with a public news API for fetching articles. You can use the GNews API and then create your own API service, with documentation, that interacts with this API for fetching articles.

The API has a few basic methods like, fetching N news articles, finding a news article with a specific title or author, and searching by keywords. Included a cache in the API service as well so users are not fetching the same things over and over.

Preparation

First, you need to create GNews API key for authorize to news API.

You just sign up to GNews and can get free API key for authentication. And store the API in .env file.

Running the application.

Download the code base from github.

git clone https://github.com/FreeFly0125/news-api-interaction.git

Then You can run the application with Docker.

docker-compose up --build

Request Body

{
  counts: number;
  title?: string;
  author?: string;
  keywords: string;
  category?: string;
  lang?: string;
  country?: string;
}

The counts and keywords fields are required, else are optional.

e.g Request body:

{
    "counts": 20,
    "keywords": "basketball, football",
    "category": "sports",
    "lang": "en"
}

By using Postman or curl, you can check the API is working.

curl -X POST http://localhost:4000/api/v1/articles/search \
    -H "Content-Type: application/json" \
    -d '{
        "counts": 20,
        "keywords": "basketball, football",
        "category": "sports",
        "lang": "en"
    }'