mesan-nodejs-crud-api-with-pagination-filtering-grouping-and-sorting-capabilities
mesan-nodejs-crud-api-with-pagination-filtering-grouping-and-sorting-capabilities copied to clipboard
Node.js REST API with CRUD and Aggregation operations including Pagination, Filtering, Grouping, Sorting and Partial Text Search.
Node.js API: CRUD operations with Pagination, Filtering, Grouping and Sorting capabilities.
Node.js REST API with CRUD and Aggregation operations including Pagination, Filtering, Grouping, Sorting and Partial Text Search.
This Branch
CRUD Operations (Event)
Other Branch
Node.js Authentication API with Email Verification
Node.js Authentication API with No Email Verification
Tutorial
Tutorial available here
API Documentation
Request parameters
-
q
- Keywords or phrases to search for in the event name - Performs Partial Text Search. -
date
- Retireve all events for the specified date. Format: YYYY-MM-DD (e.g.2020-01-08
) -
sort_order
- The order to sort the events in. Possible options: asc, desc. Default: asc -
limit
(int)- The number of results to return per page. Default: 5 -
page
(int) - Use to page through the results.
Response object
-
totalResults
(int) - The total number of results available for the request. -
limit
(int) - The limit used -
page
(int) - The current page number -
totalPages
(int) - The total number of pages available -
hasPrevPage
(boolean) - Indicates if there is a previous page -
hasPrevPage
(boolean) - Indicates if there is a next page -
prevPage
(int) - The previous page in the resultset -
nextPage
(int) - The next page in the resultset -
events
(array)- The events grouped by date. Contains JSON objects with an _id and data key.
events
-
_id
(date) - The event date -
data
(array)- The events for this date. Contains JSON objects
data
-
userId
- The identifier id for the user that created the event. -
name(string)
- The name of the event -
location
(string) - The location of the -
address
(string) - The location of the event -
start_date
(string) - The start date and time of the event -
end_date
(string) - The end date and time of the event -
description
(string) - A description or snippet from the article. -
image
(string) - The URL to a image for the event. -
createdAt
(string) - The date and time that the event was added.
Testing
Use Postman to test.
Seed Database
Populate the database with some fake data by accessing the seed endpoint. /api/event/seed . Make sure you have logged in as this endpoint requires an authentication token.
Create a GET request to /api/event/seed
Pagination and Sorting
Create GET requests
-
Get all events [default limit is 5]
http://localhost:3000/api/event
-
Page through the results
http://localhost:3000/api/event?page=2
-
Get all events in descending order
http://localhost:3000/api/event?sort_order=desc
-
Get all events with a limit of 10
http://localhost:3000/api/event?limit=10
Filtering and Grouping
Create GET requests
-
Search for an event
http://localhost:3000/api/event?q=[search_text]
-
Get all the events for a particular date - Grouped
http://localhost:3000/api/event?date=2020-07-07
-
Get all the events for a particular date - Without Grouping
http://localhost:3000/api/event?date=2020-07-07&group=0
-
Get all the events without Grouping
http://localhost:3000/api/event?group=false
Create, Read and Update
-
Create an event [POST]
http://localhost:3000/api/event
-
Read an event [GET]
http://localhost:3000/api/event
-
Update the event [PUT]
http://localhost:3000/api/event
Attempt to update an event that doesn't belong to you. Should receive an error message.
{ "message": "Event does not exist" }