Giter VIP home page Giter VIP logo

ts-express-products-api's Introduction

Products REST API

Description

Simple REST API.

Techstack

  • Express
  • Typescript
  • Mongodb
  • Mongoose

Table of contents

Prerequisities

  • node installed
  • http client

Usage

Clone repository

git clone https://github.com/wojciechszmelczerczyk/ts-express-products-api.git

Navigate to folder

cd /ts-express-products-api

Install dependencies

npm i --force

Env

Create .env file in project root directory.

# Some port number
PORT=

# MongoDB uri
DB_URI=

Run REST API

npm run dev

Postman collection

You can import provided postman collection to test api.

Architecture

Introduction

Library used to develop app architecture routing-controllers. REST API using Controller, Service and Repository approach.

GET /api/products

User send request to the server, server query database and find all products.

Example

GET /api/products/:id

User send request to the server with provided id parameter.

Middleware validate if provided id has correct syntax.

If syntax is incorrect API returns 400 with error message.

If provided id has correct syntax, middleware pass handler to the server.

Server try to query product with specific id from database.

If product doesn't exist, API respond with 400 and error message.

Example

POST /api/products

User send request to the server with name and price data.

If no data provided or data is invalid, error middleware intercept error, modify error message and return to the client with 400 status.

Otherwise new product is being returned.

Example

PUT /api/products/:id

User send request to the server with id parameter and name, price data.

Middleware validate if provided id has correct syntax.

If syntax is incorrect API returns 400 with error message.

If no data provided or data is invalid, error middleware intercept error, modify error message and return to the client with 400 status.

Otherwise updated product is being returned.

Example

DELETE /api/products/:id

User send request to the server with id parameter.

Middleware validate if provided id has correct syntax.

If syntax is incorrect API returns 400 with error message.

Otherwise handler is being passed to controller where server validate if product with provided id exists.

If not 400 with error message is returned.

When deletion of product is successful, server respond with 204 status.

Example

API

Method Endpoint
GET /api/products
GET /api/products/:id
POST /api/products
PUT /api/products/:id
DELETE /api/products/:id

ts-express-products-api's People

Contributors

wojciechszmelczerczyk avatar

Stargazers

 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.