This is a Next.js project bootstrapped with create-next-app.
This project uses json-server to mock a backend API.
Data in the json for the server is from dummyjson.com but modified to fit the needs of this project. Most of the endpoints mirrors those in that documentation.
First, install the dependencies:
npm install
# or
yarn install
# or
pnpm install
# or
bun installTo start the full development environment (Next.js frontend + JSON Server backend), use:
npm run dev:fullOpen http://localhost:3000 with your browser to see the result.
The JSON server is running on http://localhost:4000. Here you can see the API endpoints and test them.
You can start editing the page by modifying app/page.tsx. The page auto-updates as you edit the file.
This project uses json-server to mock a backend API.
The server configuration files are located in the server/ directory:
server/products.json: The database file containing the product data.server/middleware.js: Custom middleware for the server.
The following scripts are available in package.json:
npm run mock-server: Starts the json-server on port 4000.npm run dev:full: Runs both the Next.js development server and the json-server concurrently.
The mock server (running on port 4000) provides the following endpoints:
GET /products: Get all productsGET /products/:id: Get a single product by IDGET /categories: Get all categoriesGET /categories/:id: Get a category by IDGET /categories?slug=:slug: Get a category by slug
POST /products: Create a new product
Required Fields:
title: Stringprice: Numberdescription: Stringthumbnail: URL StringcategoryId: Number (ID of an existing category)brand: String
Auto-generated Fields:
id: Sequential IDsku: Generated SKU (format: CAT-BRA-TIT-ID)meta: Creation and update timestamps
See json-server documentation for more information.
Use _page and _limit to paginate data:
GET /products?_page=1&_limit=10(First page, 10 items)GET /products?_page=2&_limit=10(Second page, 10 items)
The response will include the Link header with first, prev, next, and last links.
Our custom middleware also adds X-Total-Count header and wraps the response to include pagination metadata (total, limit, page, pages).
Use _sort and _order to sort data:
GET /products?_sort=price&_order=asc(Sort by price, ascending)GET /products?_sort=price&_order=desc(Sort by price, descending)GET /products?_sort=price,title&_order=desc,asc(Sort by multiple fields)
GET /products?price_gte=10&price_lte=50(Price between 10 and 50)GET /products?q=mascara(Full-text search)
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.