/api-sample-server

Mocked store API server for frontend samples, training and experiments

Primary LanguageJavaScript

Avensia API Sample Server

Instructions

Install

$ npm i git@github.com:avensia/api-sample-server.git --save

Run

$ node_modules/.bin/api-server

# Or run `api-server` in run-script, e.g:
# ...
# "scripts": {
#   "start": "api-server | webpack"
# }
# ...

$ npm start

Then the server is running on the default port, 8181. You can change the port with the environment variable SERVER_PORT.

$ SERVER_PORT=8282 node_modules/.bin/api-server

API

No parameters

Responds with an Array containing all products.

GET /products/:id

No parameters

Responds with product identified with the given :id.

No parameters

Responds with full cart. Cart items and summary.

DELETE /cart

No parameters

Empty cart. Responds with full updated cart.

POST /cart/:id

Parameters: quantity=[number]

Add quantity to item with product identified with :id. Responds with full updated cart.

PUT /cart/:id

Parameters: quantity=[number]

Update quantity to item with product identified with :id. If item doesn't exist in cart, it will be added with the given quantity. Responds with full updated cart.

DELETE /cart/:id

No parameters

Remove item with :id. Responds with full updated cart.

Models

Product

type Product = {
  id: number;
  title: string;
  imageUrl: string;
  url: string; // Absolute URL to API
  prices: Price[];
};

type Price = {
  amount: number;
  currency: string; // Currently SEK and EUR
};

Cart

type Cart = {
  items: Item[];
  summary: Price[];
}

type Item = {
  product: Product;
  quantity: number;
};