Sample REST API written in Node.js to show some of the best practices as design patterns, testing and appropriate architecture.
- 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
$ cd [your project path]
$ nmp install
- Install mocha globally
$ npm install -g mocha
$ cd [your project path]
$ node app.js
$ cd [your project path]
$ mocha
- 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"
}
]
- MVC presentation layer pattern
- End to End Testing
- Jorge Sánchez Fernández aka xurxodev
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.