Skip to content

Latest commit

 

History

History

server

Back-end

Init server

Development

Install Denon:

deno install -qAf --unstable https://deno.land/x/denon@2.4.4/denon.ts

and run the development server:

denon dev

Production

Create a .env file and add the follow environment variables:

PORT=[YOUR PORT NUMBER]

PG_HOST=[POSTGRES HOST]
PG_USER=[POSTGRES USERNAME]
PG_PASSWORD=[POSTGRES PASSWORD]
PG_DATABASE=[POSTGRES DATABASE]

follow the .env.example model.

and run the production server:

deno run --allow-read --allow-write --allow-net src/app.ts

to use SSL see Use HTTPS topic

With Docker

to run the production server with Docker, install Docker and docker-compose, and run:

docker-compose up

Use HTTPS

To use HTTPS you need to create a folder src/ssl, and add your certificate and key inside src/ssl, with the names cert.pem and key.pem.

Then, you need to start de server with the flag --secure:

deno run --allow-read --allow-write --allow-net src/app.ts --secure

API

Create

route: POST /clothes

request body:

JSON:
  product: Description of the product - string
  brand: Product brand - string
  quantity: Quantity of product purchased - number
  provider: Product Provider - string
  price: Price of the product - float
  currentInventory: Current stock available - number
  size: Size of the product - string
  inputValues: Profit obtained - float
  outputValues: Product spending - float

e.g.:

{
  "product": "CROPPED COURINO PRETO",
  "brand": "ANTONY",
  "quantity": 2,
  "provider": "Luana",
  "price": 20.00,
  "currentInventory": 2,
  "size": "G,M",
  "inputValues": 20.00,
  "outputValues": 20.00
}

expected response status code: 201

Index

route: GET /clothes

request body: NO BODY

expected response status code: 200

expected response body:

ARRAY OF JSON:
  product: Description of the product - string
  brand: Product brand - string
  quantity: Quantity of product purchased - number
  provider: Product Provider - string
  price: Price of the product - float
  currentInventory: Current stock available - number
  size: Size of the product - string
  inputValues: Profit obtained - float
  outputValues: Product spending - float

Show

route: GET /clothes/:id

request body: NO BODY

expected response status code: 200

expected response body:

JSON:
  product: Description of the product - string
  brand: Product brand - string
  quantity: Quantity of product purchased - number
  provider: Product Provider - string
  price: Price of the product - float
  currentInventory: Current stock available - number
  size: Size of the product - string
  inputValues: Profit obtained - float
  outputValues: Product spending - float

Delete

route: DELETE /clothes/:id

request body: NO BODY

expected response status code: 200

Update

route: PUT /clothes/:id

request body:

JSON:
  product: Description of the product - string
  brand: Product brand - string
  quantity: Quantity of product purchased - number
  provider: Product Provider - string
  price: Price of the product - float
  currentInventory: Current stock available - number
  size: Size of the product - string
  inputValues: Profit obtained - float
  outputValues: Product spending - float

e.g.:

{
  "product": "CROPPED COURINO PRETO",
  "brand": "ANTONY",
  "quantity": 2,
  "provider": "Luana",
  "price": 20.00,
  "currentInventory": 2,
  "size": "G,M",
  "inputValues": 20.00,
  "outputValues": 20.00
}

expected response status code: 200