/simple-api

simple-api with typscript and mysql

Primary LanguageTypeScript

Simple - API

A simple web API to demonstrate relationship of customer and product in a database

Database Scheme

Database scheme is located here

Run Locally

Prepare Database - The API has been tested with MySQL & Postgress database, but I believe it can work with any database. Check out TypeORM for more information. (Make sure your preferable database is installed)

Create database

    mysql -u root -p;
    CREATE DATABASE simple_api;

Configure TypeORM Edit the ormconfig.json file located in the root of the project with your databse crediatials. for example:

   "type": "mysql",
   "host": "localhost",
   "port": 3306,
   "username": "root",
   "password": "admin",
   "database": "simple_api",
   "synchronize": true,
   "logging": false,
   ...

Install dependencies

  yarn

  // or

  mpm install

Load test data to the database

  yarn run loadData

Start the server

  yarn run dev

The port is 1337, you can change it at config file. visit localhost:1337

API Reference

Get all simcards

  GET /sim-cards
Parameter Type Description
none json list all simcards

Create new order

  POST /orders
Parameter Type Description
data json create order in database

Get all orders

  GET /orders
Parameter Type Description
none json list all orders

Update an Order

  PUT /orders/:id
Parameter Type Description
data json update an existing order in database