DEV Community

Cover image for ECOMMERCE Website Using MERN Part-5.1 ( Api Features {Setup} )
Bikramjeet Sarmah
Bikramjeet Sarmah

Posted on

ECOMMERCE Website Using MERN Part-5.1 ( Api Features {Setup} )

In these Parts we are gonna start making our Api Features like Search, Pagination etc

In this blog we will just setup our API Feature class

Step-1 Make a file named apiFeatures.js in the utils folder.

Step-2 Inside that file lets make a class named ApiFeatures and export that as an module.
Setup

Step-3 Inside of the class lets make a constructor with two parameters query & queryStr and assign them to query & queryStrof the same class.
Query String

Here the query is our query like Product.find() etc and queryStr will be the keyword with its value
Query Str

Now Open the productController and import the apiFeature.
Import

Now lets use this apiFeature in getAllProduct function.
Use
Here the first parameter is the query and second parameter is the queryStr

Our Setup is completed, so in the next blog we will be making our first feature which will be Searching

Next Blog

Discussion (0)