This repository contains sample code on how to do dependency injection with the awilix framework.
This repository is part of the Dependency Injection in Node tutorial series provided by productioncoder.com.
For updates, please reach out to @_jgoebel on Twitter.
Make sure to install the dependencies with npm
npm install
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)
You can then run the project by executing
npm run dev
Expected payload
{
"email": "john@example.com",
"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
returns a developer associated with the specified id
.
Response format:
{
"email": "john@example.com",
"firstName": "John",
"middleNames": "Alexander Tom",
"lastName": "Smith"
}