This is the API building assignment given by Mobilicis India Private Limited, in which i have used NEXT.Js and Tailwind CSS for the frontend, and i have used Express and MongoDB for the backend, the assignment required me to query the sample dataset and give some insightful APIs through the website, which i have successfully executed. I have deployed the website via Vercel and the URL to the working API providing website is - https://mobilicis-assignment-eta.vercel.app/
I have written the server code in the API directory provided by NEXT.Js which supplies all the APIs to the website, there are 5 endpoints in the website, each corresponds to the questions asked in the assignment word file.
These endpoints have been then rendered server side before the page loads via the getServerSideProps
method of NEXT.Js, which is a crucial part in making the API fast and reduce the load time, you can see the results of the API call in just Milliseconds after you press one of the buttons in the website.
Below are the API Endpoints for each of the questions in the word file, respectively, I would recommend to visit the site first to visualize the data in table format first and then going to the below links to see the working of the API endpoints. Visit the links below to view the JSON objects output of the dataset.
Lets understand the working of the endpoints by considering fourth question's server code
import dbConnect from "@/utils/mongo";
import Assignment from "@/models/Assignment";
export default async function handler(req, res) {
await dbConnect();
if (req.method == "GET") {
try {
const dataset = await Assignment.find({
car: { $in: ["BMW", "Mercedes", "Audi"] },
email: { $exists: true, $not: /[\d]/ },
});
res.status(200).json(dataset);
} catch (error) {
res.status(500).json(error);
}
}
}
dbConnect
function is a mongodb Atlas connection establishment function which is imported from the utils directory of the website, which ensures that there is successfull connection between the website and the database.Assignment
model is the overall model of the object of the dataset for retrieval and query purposes.try
block of the above code segment, in the above case, i have queried for the objects/users, who own either a 'BMW', 'Mercedes' or an 'Audi' and do not have any digits in his/her email.getServerSideProps
function is run in the index.js file in the pages directory of the website.Then, run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev