Giter Site home page Giter Site logo

michalzagrodzki / dinner-api Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 247 KB

API server for React-dinner repo

JavaScript 100.00%
nodejs nodejs-server nodejs-api es6 microservices rest-api starter express express-boilerplate mongoose mongodb swagger domain-driven-design

dinner-api's Introduction

Node.js REST API for Dinners App

This repository is an example for REST API built with Express.js, MongoDB.

Key concepts

  • This project is ready to work with any clientside app
  • Architecture follows Domain Driven Design
  • Code structured in modules
  • Body field validators
  • Params validators

Tech stack

Node.js, Express.js, MongoDB

Running project

Clone repository:

git clone [email protected]:michalzagrodzki/dinner-api.git

Install dependencies:

npm install

Run project:

npm run start

Project models

Project has three following models: Dinners, Ingredients, Orders.

Dinners:

const dinnerSchema = new Schema({
  title: { type: String, required: true },
  price: { type: String, required: true },
  weight: { type: Number, required: true, min: 0 },
  calories: { type: Number, required: true, min: 0 },
  ingredients: [{ type: Schema.Types.ObjectId, ref: "Ingredient" }],

Orders:

const orderSchema = new Schema({
  title: { type: String },
  dinner_id: { type: Schema.Types.ObjectId, ref: "Dinner" },
  client_name: { type: String, required: true },
  client_phone: { type: String, required: true },
  client_email: { type: String },
  price: { type: String, required: true },
  calories: { type: Number, required: true, min: 0 },
  weight: { type: Number, min: 0 },
  ingredients: [{ type: Schema.Types.ObjectId, ref: "Ingredient" }],
});

Ingredients:

const ingredientSchema = new Schema({
  name: { type: String, required: true },
  price: { type: String, required: true },
  calories: { type: Number, required: true, min: 0 },
});

Environment variables

Environment variables are located in .env file

# URL of the Mongo DB
DB_URI=mongodb://127.0.0.1:27017/dinner-api

API Documentation

API endpoints and their specifications are available through following link: http://localhost:2000/api/v1/api-docs/ in your browser. This documentation page is generated using the swagger definitions written as yaml files.

API Endpoints

List of available routes:

Dinner routes:
POST /v1/dinners - create a dinner
GET /v1/dinners - get all dinners
GET /v1/dinners/:dinnerId - get dinner
PUT /v1/dinners/:dinnerId - update dinner
DELETE /v1/dinners/:dinnerId - delete dinner

Ingredient routes:
POST /v1/ingredients - create an ingredient
GET /v1/ingredients - get all ingredients
GET /v1/ingredients/:ingredientId - get ingredient
PUT /v1/ingredients/:ingredientId - update ingredient
DELETE /v1/ingredients/:ingredientId - delete ingredient

Order routes:
POST /v1/orders - create an order
GET /v1/orders - get all orders
GET /v1/orders/:orderId - get order
PUT /v1/orders/:orderId - update order
DELETE /v1/orders/:orderId - delete order

dinner-api's People

Contributors

michalzagrodzki avatar

Watchers

 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.