This is a Node.js Express API that provides endpoints for fetching blog statistics and performing blog searches. It uses memoization to optimize certain operations.
- Clone this repository to your local machine.
- Run
npm install
to install the required dependencies.
To fetch blog statistics, make a GET request to /api/blog-stats
.
Example Request:
GET /api/blog-stats
Example Response:
{
"totalNumberOfBlogs": 10,
"longestTitle": "The Longest Blog Title Ever",
"numberOfBlogsWithPrivacyInTitle": 3,
"numberOfUniqueTitles": 8,
"uniqueBlogTitles": ["Blog Title 1", "Blog Title 2", ...]
}
To perform a blog search, make a GET request to /api/blog-search
with a query
parameter.
Example Request:
GET /api/blog-search?query=privacy
Example Response:
{
"results": [
{
"id": 1,
"image_url": "https://picsum.photos/200/300",
"title": "Blog Title 1",
},
{
"id": 2,
"image_url": "https://picsum.photos/200/300",
"title": "Blog Title 2",
},
...
]
}
If the query parameter is missing, a 400 Bad Request response will be returned.
This API uses memoization to optimize the following operations:
- Blog statistics calculation using the
memoizedFetchAndAnalyzeBlogStats
function - Blog search using the
memoizedPerformBlogSearch
function
Memoization caches the results of these operations to improve performance.
To run the server,run the following command:
node app.js
The server will be running on port 8000.