Giter VIP home page Giter VIP logo

building-a-node-express.js-rest-api-server-using-a-repository-pattern's Introduction

Building a Node + Express.js Rest API server using a repository pattern

This is a complete example of a Rest API server which manages two collections: Post and BlogCategory.

Both are defined on app.js file and for the CRUD operations share the same route modules on routes folder. Their specific data mappers and repositories are created outside and passed using the dependency injection.

Routes objects validate their parameters or body data with the validators on routes/validators and dialog with the database using the injected repository methods.

In each collection a resource is identified by an unique id created with the UID lib.

The data transfer objects definitions are on dto folder and each of them has an own mapper to a repository entity object defined on entities folder. The mapping operations among dto objects and entities are performed by routes before sending and after receiving repository data.

The database used for development and testing purpose is ForeRunnerDB and the repository classes are on repositories/ForeRunnerDB folder. For other databases support it would be enough to write a new specific repository class and inject it on route creation.


Getting Started

The test server is a Node/Express.js app running on localhost:4000. If you want to modify the app port, change the configuration file config/default.yaml.

Data are saved using the database ForerunnerDB.

The tests on test/e2e folder show the different API usage.


Prerequisites

What things you need to install the software

Node.js 6.0+

Installing

The easiest way to get started is to clone the repository:

# Get the latest snapshot
git clone https://github.com/claclacla/Building-a-Node-Express.js-Rest-API-server-using-a-repository-pattern

# Change directory
cd Building-a-Node-Express.js-Rest-API-server-using-a-repository-pattern

# Install NPM dependencies
npm i

Usage

# Change directory
cd Building-a-Node-Express.js-Rest-API-server-using-a-repository-pattern

# Start the API server using node
npm start

# Test it using...

npm run unit-test
# ...to test server code

npm run e2e-test
# ...to test the collections API

Authors


License

This project is licensed under the MIT License


Acknowledgments

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.