Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Article Management API

This project is a simple Express.js API for managing and searching articles. The API allows you to add articles, view all articles, search for specific articles by title or keyword, and fetch articles by ID.

Features

  • Add articles with a unique ID, title, and text.
  • Retrieve all articles.
  • Search for articles by title or keyword and sorts them based on keyword frequency.
  • Get details of a specific article by its ID.

Installation

  1. Clone the repository.
  2. Install dependencies:
    npm install
  3. Start the server:
    node index.js

The server will run on http://localhost:3000.

API Routes

GET /

Description: Returns a message indicating that the API is running.

Response:

"Article API is running"

POST /articles

Description: Adds a new article to the list.

Request Body:

{
  "id": "<unique_id>",
  "title": "<article_title>",
  "text": "<article_text>"
}

Responses:

  • Success:
    { "message": "success" }
  • Failure:
    { "message": "failed. Invalid article format" }

GET /viewarticles

Description: Returns the list of all articles.

Response:

{
  "articles": [
    {
      "id": "<id>",
      "title": "<title>",
      "text": "<text>"
    },
    ...
  ]
}

GET /getarticle

Description: Fetches a specific article by its ID.

Query Parameters:

  • id: The unique ID of the article.

Responses:

  • Success:
    { "article": { "id": "<id>", "title": "<title>", "text": "<text>" } }
  • Failure:
    { "error": "article not found" }

GET /search

Description: Searches for articles by title or keyword in the text.

Query Parameters:

  • title: The title of the article to search for.
  • key: A keyword to search for in the article text.

Responses:

  • Search by Title (Success):
    { "article": { "id": "<id>", "title": "<title>", "text": "<text>" } }
  • Search by Keyword (Success):
    {
      "articles": [
        {
          "book": { "id": "<id>", "title": "<title>", "text": "<text>" },
          "keyfreq": <frequency>
        },
        ...
      ]
    }
  • Failure:
    { "message": "failed" }

Helper Functions

getfreq(key, para)

Counts the frequency of a keyword (key) in a paragraph (para).

sortList(lst)

Sorts a list of articles by the frequency of the keyword in descending order.

Example Usage

  1. Add an article:
    curl -X POST http://localhost:3000/articles \
    -H "Content-Type: application/json" \
    -d '{"id": "1", "title": "Hello World", "text": "hello hello world"}'
  2. View all articles:
    curl http://localhost:3000/viewarticles
  3. Search for an article by title:
    curl "http://localhost:3000/search?title=Hello%20World"
  4. Search for an article by keyword:
    curl "http://localhost:3000/search?key=hello"

About

Article Search Engine for Skill Lab MileStone

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages