Feed Search and Sort API
This project implements a backend API for searching, sorting, and paginating a feed. It allows searching in fields name
and description
and supports exact match when the query contains a phrase within double quotes. The API also provides sorting options for name
and dateLastEdited
.
Table of Contents
Before running the project, make sure you have the following installed:
- Node.js (v14 or later)
- npm (Node Package Manager)
- Clone the repository:
git clone https://github.com/nehakalbande/FeedSearch.git
cd FeedSearch
- Install dependencies:
npm install
- Start the server:
node app.js
The server will start running at http://localhost:3000
.
The API provides the following endpoints:
GET /api/posts
: Search, sort, and paginate the feed.
For detailed documentation on how to use each endpoint, please refer to the API Endpoints section below.
Search, sort, and paginate the feed.
Query Parameters:
q
(optional): Search term. If not provided, all posts match the query. Supports exact match with double quotes.sortBy
(optional): Sort the posts byname
ordateLastEdited
. Default isname
.page
(optional): Page number for pagination. Default is1
.
Response:
{
"posts": [
{
"name": "Post 1",
"description": "Description of Post 1",
"dateLastEdited": "2023-07-23T14:30:00.000Z"
},
// Other posts...
],
"totalCount": 100,
"totalPages": 20,
"currentPage": 1
}
To run the unit and integration tests, use the following command:
npm test
http://localhost:3000/api/posts?q="The Lord of the Rings: The Return of the King"
http://localhost:3000/api/posts?page=2
http://localhost:3000/api/posts?q=the king&sortBy=name&page=1