GithubHelp home page GithubHelp logo

product-node-api's Introduction

Product Node API

Sample REST API written in Node.js to show some of the best practices as design patterns, testing and appropriate architecture.

Setup

Install Node.js and clone project

  • Download from [Node.js web](brew install node) or from brew for OSX brew install node
  • git clone https://github.com/xurxodev/Catalog-API.git

Install modules and mocha

  • $ cd [your project path]
  • $ nmp install
  • Install mocha globally $ npm install -g mocha

Run API REST

  • $ cd [your project path]
  • $ node app.js

Run tests running API REST previously

  • $ cd [your project path]
  • $ mocha

Products endpoint

  • POST /api/products
POST /api/products HTTP/1.1
Host: localhost:8080
Content-Type: application/json
Cache-Control: no-cache

{
    "sku": "ab48cicj36734",
    "asin": "B015E8UTIU",
    "upc": "888462500449",
    "title": "Apple iPhone 6s 64 GB US Warranty Unlocked Cellphone - Retail Packaging (Rose Gold)",
    "image": "http://ecx.images-amazon.com/images/I/91DpCeCgSBL._SL1500_.jpg"
}
HTTP/1.1 201 Created
Connection: keep-alive
Content-Length: 29
Content-Type: application/json
Date: Thu, 24 Dec 2015 16:42:23 GMT
Location: /api/products/ab48cicj36734
  • GET /api/products
GET /api/products HTTP/1.1
Host: localhost:8080
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 233
Content-Type: application/json
Date: Thu, 24 Dec 2015 16:46:26 GMT

[
  {
    "sku": "ab48cicj36734",
    "asin": "B015E8UTIU",
    "upc": "888462500449",
    "title": "Apple iPhone 6s 64 GB US Warranty Unlocked Cellphone - Retail Packaging (Rose Gold)",
    "image": "http://ecx.images-amazon.com/images/I/91DpCeCgSBL._SL1500_.jpg"
  }
]

Best practices used

  • MVC presentation layer pattern
  • End to End Testing

Libraries used on the sample project

Developed By

  • Jorge Sánchez Fernández aka xurxodev

License

Copyright 2015 Jorge Sánchez Fernández

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

product-node-api's People

Contributors

xurxodev avatar

Stargazers

Diego Alexander Londoño avatar Hery avatar

Watchers

James Cloos avatar  avatar

product-node-api's Issues

Error running app.js

After doing npm install, I get this error running api rest:

    throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor', 'Function');
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "superCtor" argument must be of type Function
    at Object.inherits (util.js:947:11)
    at Object.<anonymous> (/home/jiglesias/Projects/nodepoc/Product-Node-API/node_modules/spdy/lib/spdy/connection.js:86:6)
    at Module._compile (module.js:662:30)
    at Object.Module._extensions..js (module.js:673:10)
    at Module.load (module.js:575:32)
    at tryModuleLoad (module.js:515:12)
    at Function.Module._load (module.js:507:3)
    at Module.require (module.js:606:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/jiglesias/Projects/nodepoc/Product-Node-API/node_modules/spdy/lib/spdy.js:20:19)```

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.