Coder Social home page Coder Social logo

venkat230407 / node-typescript-boilerplate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ofuochi/node-typescript-boilerplate

0.0 0.0 0.0 365 KB

An enterprise startup boilerplate for typescript and nodejs API project

License: MIT License

TypeScript 100.00%

node-typescript-boilerplate's Introduction

NodeJs/Typescript API Boilerplate

For Enterprise

Running the app

NOTE: These instructions require MongoDB and Node.js to be installed on your environment.

Clone the Repository:

git clone https://github.com/ofuochi/node-typescript-boilerplate.git
cd node-typescript-boilerplate

Create Your Branch

git checkout -b <INSERT-BRANCH-NAME>

Install Dependencies:

npm install

Copy Files

Sample env File into a .env File:

cp env.sample .env

Run the App:

npm run start

Open:

http://localhost:3000/api/v1/tenants

Run Tests:

npm run test

REST Services

The application exposes a few REST endpoints which requires you to pass x-tenant-id header. First call the tenant endpoint /api/v1/tenant to get all the available tenants. Use any of the tenant IDs as the value for x-tenant-id

  • HTTP GET /api/v1/tenats
  • HTTP GET /api/v1/tenats/:query
  • HTTP GET /api/v1/secured (Requires a valid x-auth-token header)

You can use the following code snippet to call the secured endpoint:

fetch("http://localhost:3000/api/v1/secure", {
    method: "GET",
    headers: {
        "Content-Type": "application/json",
        "x-tenant-id": "TENANT_ID",
        "x-auth-token": "SOME_VALID_CREDENTIAL"
    }
})
    .then(r => {
        if (r.status === 200) {
            r.json().then(j => console.log(j));
        } else {
            console.log("ERROR", r.status);
        }
    })
    .catch(e => console.log(e));

You can use the following code snippet to call the secured endpoint with an invalid x-auth-token header:

fetch("http://localhost:3000/api/v1/secure", {
    method: "GET",
    headers: {
        "Content-Type": "application/json",
        "x-tenant-id": "TENANT_ID",
        "x-auth-token": "SOME_WRONG_CREDENTIAL"
    }
})
    .then(r => {
        if (r.status === 200) {
            r.json().then(j => console.log(j));
        } else {
            console.log("ERROR", r.status);
        }
    })
    .catch(e => console.log(e));

node-typescript-boilerplate's People

Contributors

artfuldev avatar fabianopb avatar irmerk avatar ofuochi avatar rugglcon avatar tayormi 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.