Code Monkey home page Code Monkey logo

node-dependency-injection's Introduction

Dependency Injection in Node with awilix

This repository contains sample code on how to do dependency injection with the awilix framework.

Please help this repo with a โญ๏ธ if you find it useful! ๐Ÿ˜

This repository is part of the Dependency Injection in Node tutorial series provided by productioncoder.com.

Request body validation in Node

For updates, please reach out to @productioncoder on Twitter.

How to run this application

Running the project

Install dependencies

Make sure to install the dependencies with npm

npm install

Running a local Postgres instance

Make sure that you have a local Postgres instance running and that you execute the SQL statment in the migrations directory.

After you have created the tables, make sure that you update the config/index.js file with your Postgres configuration (hostname, port, password, etc)

Starting up the local server

You can then run the project by executing

npm run dev

API

POST /dev

Expected payload

{
    "email": "[email protected]",
    "firstName": "John",
    "middleNames": "Alexander Tom",
    "lastName": "Smith"
}

The server will return a 400 bad request error if the request body does not conform to the expected DTO (data transfer object).

This endpoint will normalize the firstName field by truncating the whitespace and by moving all names after the first space to the middle names field.

Please check out the ./dto directory to learn more about the expected request body.

GET /dev/:id

GET /dev/:id returns a developer associated with the specified id. Response format:

{
    "email": "[email protected]",
    "firstName": "John",
    "middleNames": "Alexander Tom",
    "lastName": "Smith"
}

node-dependency-injection's People

Watchers

James Cloos 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.