Skip to content

Express REST API featuring Prisma ORM, session-based authentication and integration testing with Mocha, Chai + SuperTest. Designed with Swagger tools and documented with OpenAPI 3.0.3.

Notifications You must be signed in to change notification settings

majid-L/express-ecommerce-api

Repository files navigation

Express, TypeScript, Prisma ORM and OpenAPI project

This project features a RESTful CRUD API that processes data for an ecommerce application.

Key product features

                             


Endpoints

For more information on available query parameters and request body requirements, visit the API base url.

Many of these endpoints require authenticated access, which you can accomplish by first signing up and then logging in.

// 1) Send a POST request to /api/signup
{
  "username": ...,
  "password": ...,
  "email": ... ,
  "name": ...
}

// 2) Send a POST request to /api/login
{
  "username": ... /* your username from step 1) */,
  "password": ... /* your password from step 1) */
}
HTTP method(s) URL
POST /api/signup
POST /api/login
POST /api/logout
GET /api/products
GET /api/products/bestsellers
GET /api/products/:id
GET /api/products/:id/reviws
GET, PUT, DELETE /api/customers/:id
GET, PUT /api/customers/:id/cart
GET, PUT /api/customers/:id/wishlist
GET, POST /api/customers/:id/orders
GET /api/customers/:id/favorites
GET /api/customers/:id/orders/:orderId
GET /api/customers/:id/reviews
POST /api/customers/:id/addresses
DELETE /api/customers/:id/addresses/:addressId
GET /api/categories
GET /api/suppliers
GET, POST /api/reviews
GET, PUT, DELETE /api/reviews/:id

Data model

This is a simplified view of the entity relationships that exist within the database. For a more complete picture, consult the schema configuration and migration files.


Main project dependencies

Package Purpose
Express Web API framework
Prisma Node.js & TypeScript ORM
SuperTest Integration testing
Mocha Test framework
Chai Assertion library
Passport.js Authentication middleware
express-session Session middleware

Running the project on localhost

This project requires PSQL to be installed locally.

Setup instructions

  1. Clone and fork the repository and install all dependencies.
  2. Create a local empty PSQL database called ecommerce_db.
  3. Create a .env file in the root of the repository with 4 environment variables:
DATABASE_PRISMA_URL=postgresql://<USER>:<password>@localhost:5432/ecommerce_db
DATABASE_URL_NON_POOLING=postgresql://<USER>:<password>@localhost:5432/ecommerce_db
SESSION_SECRET=sessionsecret
PORT=3000
  1. For the database connection strings, Replace <USER> with the name of your local database user (e.g. postgres) and replace <PASSWORD> with whatever password you used to set up the local user.

You can now run the scripts below and begin to explore the project.

Run the Express server in development mode.

npm run dev

# or

npm run start

Compile and run Mocha test suite

npm run test

Test coverage report

npm run testcov

Update database schema

This command performs 2 actions: syncs the database schema with Prisma schema and regenerates Prisma Client.

npx prisma migrate dev

# or

prisma db push

Seed database

npx prisma db seed

Prisma Studio (browser-based GUI and database visualiser)

npx prisma studio

About

Express REST API featuring Prisma ORM, session-based authentication and integration testing with Mocha, Chai + SuperTest. Designed with Swagger tools and documented with OpenAPI 3.0.3.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published