Node.js REST API with CRUD and Aggregation operations including Pagination, Filtering, Grouping, Sorting and Partial Text Search.
CRUD Operations (Event)
Node.js Authentication API with Email Verification
Node.js Authentication API with No Email Verification
Tutorial available here
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: asclimit
(int)- The number of results to return per page. Default: 5page
(int) - Use to page through the results.
totalResults
(int) - The total number of results available for the request.limit
(int) - The limit usedpage
(int) - The current page numbertotalPages
(int) - The total number of pages availablehasPrevPage
(boolean) - Indicates if there is a previous pagehasPrevPage
(boolean) - Indicates if there is a next pageprevPage
(int) - The previous page in the resultsetnextPage
(int) - The next page in the resultsetevents
(array)- The events grouped by date. Contains JSON objects with an _id and data key.
_id
(date) - The event datedata
(array)- The events for this date. Contains JSON objects
userId
- The identifier id for the user that created the event.name(string)
- The name of the eventlocation
(string) - The location of theaddress
(string) - The location of the eventstart_date
(string) - The start date and time of the eventend_date
(string) - The end date and time of the eventdescription
(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.
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" }