Coder Social home page Coder Social logo

catalog's Introduction

CATALOG API

Context

Small Catalog API project using nest.js & sqlite as DB.

This API allows you to see and buy products from a catalog.

Some products are only available for connected users, others are available for all users.

Features

  • Authentication using JWT
  • Get all products
  • get one product
  • Add products to cart
  • get user cart
  • update product quantity in cart
  • delete product from cart

The DB is already populated with users, to have an authorized access use one of the following credentials:

{
	"email": "[email protected]",
	"password": "1bonjour"
}

PS: all users use the same password format: id + bonjour

Installation

First install dependencies:

npm ci

Then run the server:

npm run start

a debug version is also available:

npm run start:dev

It will allow you to have startup logs and to see the server errors.

a production ready version is also available:

npm run start:prod

It'll build the project (compile ts files) and run the server.

Calls examples

Those curl calls can be imported in your Insomnia workspace, Postman or used directly in your terminal.

For all calls requiring authentication, you need to provide the JWT token in the header. The following example will use an already existing JWT, if not working yuo should log yourself in and use the returned JWT.

Login:

User a different user as you please

curl --request POST \
--url http://localhost:3000/auth/login \
--header 'Content-Type: application/json' \
--data '{
"email": "[email protected]",
"password": "1bonjour"
}'
Get all public products:
curl --request GET \
--url http://localhost:3000/products
Get all private products:
curl --request GET \
--url http://localhost:3000/products/authenticated \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJqZWFubWljaGVsQGFpcndlYi5mciIsImlhdCI6MTY1MDI4MTg3OCwiZXhwIjoxNjU1NDY1ODc4fQ.cdJOhqyNWZPdahO4c0pJzyzzZR-QDt4kRDsr7s-wVnY'
Add to cart:

Change the productId and quantity as you please

curl --request POST \
--url http://localhost:3000/carts \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJqZWFubWljaGVsQGFpcndlYi5mciIsImlhdCI6MTY1MDI4MTg3OCwiZXhwIjoxNjU1NDY1ODc4fQ.cdJOhqyNWZPdahO4c0pJzyzzZR-QDt4kRDsr7s-wVnY' \
--header 'Content-Type: application/json' \
--data '{
"productId": 2,
"quantity": 10
}'
Get User cart:
curl --request GET \
--url http://localhost:3000/carts \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJqZWFubWljaGVsQGFpcndlYi5mciIsImlhdCI6MTY1MDI4MTg3OCwiZXhwIjoxNjU1NDY1ODc4fQ.cdJOhqyNWZPdahO4c0pJzyzzZR-QDt4kRDsr7s-wVnY'

catalog's People

Contributors

sufiane avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.