Javascript Basic RESTful
-
Upload
sofian-hadiwijaya -
Category
Technology
-
view
637 -
download
0
Transcript of Javascript Basic RESTful
Jakarta JS
Back to Basic of Node.js and Reactivity
RESTful API with Node.js + MongoDB
About Me
• Name : Sofian Hadiwijaya
• Email : [email protected]
• Blog : http://www.sofianhw.com
• Id : sofianhw
Basic - RESTfulWikipedia, that infallible source, defines Representational State Transfer (REST) as: an architectural style that abstracts the architectural elements within a distributed hypermedia system.
Basic - RESTfulFour basic design principles from IBM's developerWorks website
1.Use HTTP methods explicitly2.Be Stateless3.Expose directory structure-like URIs4.Transfer XML or JSON, or Both
Basic - Express JSA minimal and flexible node.js web application framework, providing a
robust set of features for building full web applications and/or APIs.
$ npm install express• Middleware• Routing
Basic - ExpressExpress Hello World
Basic - ExpressA router object is an isolated instance of middleware and routes, capable only of performing middleware and routing functions. A router behaves like middleware itself, so you can use it as an argument to app.use() or as the argument to another router’s use() method. Every Express application has a built-in app router:
Basic - ExpressChainable route handlers for a route path can be created using app.route().Since the path is specified at a single location, it helps to create modular routes and reduce redundancy and typos.
Basic - Mongooseelegant mongodb object modeling for node.js
$ npm install mongoose
Build Basic RESTfulVery simple file structure
Defining Node Packages
Build Basic RESTfulClone repository
$ git clone https://github.com/sofianhw/simple-restful-nodejs.git
Install packages with $ npm install
Running Script $ npm start
Model
Routes
Basic Testing - MochaMocha is a simple, flexible, fun JavaScript test framework for node.js and
the browser.
$ npm install -g mocha
Basic Testing - Shouldshould is an expressive, readable, framework-agnostic assertion library. The main goals of this library are to be expressive and to be helpful. It keeps your test code clean, and your error messages helpful.
$ npm install should
Basic Testing - SupertestHTTP assertions made easy via super-agent
$ npm install supertest