Advertisement
Advertisement

More Related Content

Advertisement
Advertisement

Building RESTtful services in MEAN

  1. Building RESTful services in MEAN
  2. ● Madhukara Phatak ● Big data and FP consultant ● Spark,Hadoop and ecosystem ● @madhukaraphatak ● www. madhukaraphatak.com
  3. Agenda ● What is a stack? ● LAMP stack ● MEAN stack ● LAMP vs MEAN ● Why MEAN? ● MEAN technologies ● Hands on
  4. Stack ● Set of independent tools working together to solve a specific problem ● These tools can be used in other settings ● But when they are used together, they result in something elegant and useful ● Ex : LAMP, MEAN etc
  5. LAMP stack ● Linux operating system ● Apache web server ● MySQL database ● php for web programming A stack for building powerful websites.
  6. Variation in LAMP ● Tomcat, Glassfish in place of Apache ● Oracle, Postgresql in place of Mysql ● Servlets, ASP.net in place of Php All of these share common idea of web development.
  7. MEAN stack ● V8 is the operating system ● MongoDB is for the storage ● Express for the web programming ● Angular is for the frontend development ● Node for the web server Powerful stack to build RESTful CRUD applications.
  8. LAMP MEAN Linux V8 engine Apache web server Node Mysql Mongodb Php Express
  9. Why MEAN? ● Building RESTful APIs in a typical LAMP stack is too much of work... ● Single language rules entire stack ● LAMP is build for websites, not for web applications ● Lot’s of fun...
  10. REST ● REpresentational State Transfer ● Architectural way of creating API on web ● Used in web services ● Component ○ URI ○ medium primarily json but formats like xml also can be used ○ HTTP methods for operation
  11. Meaning of REST URI - http://www.example.com/resource ● Get - get collection ● Put - replace collection ● Post - add a new entry to collection ● Delete - delete the collection http://www.example.com/resource/1234 is a way to deal with specific element in the collection
  12. REST in LAMP Client (Browser) Server ( GSON to JSON Java Objects) ORM (Hibernate) Mysql (Tables) Challenges 1. Adding a new field 2. Mapping nested json to RDBMS schema 3. Lost in translation
  13. REST in MEAN Client (Browser) JSON Server JSON Mongodb (JSON) Advantages 1. Adding a new field 2. Mapping nested JSON to Mongodb schema 3. No translation need
  14. JSON is the secret sauce of MEAN ● Every component in MEAN stack talks in JSON ● Having JSON as the standard makes life very easy for a developer ● Javascript is the language where json is default ● With mongodb, even databases going in JSON direction.
  15. What MEAN is good for ● CRUD web applications ● REST API servers ● Single page apps ● Static content servers Actually anything I/O Bound.
  16. What MEAN is not good for? ● Computation intensive applications ● Number crunching machines ● Transactional systems etc
  17. Read it later service ● Allow you to save links to read it later ● You can add links from browser, phone etc ● Uses REST API to communicate ● Ex : Instapaper, pocket ( read it later)
  18. Node.js ● Javascript Runtime ● Written in C/C++ ● Runs on V8, Javascript VM for Chrome ● Follows module structure ● Modules can be written both in JS/C ● npm is module manager
  19. Async programming ● Every node.js program is a series of events ● Each event completes asynchronously ● Each event will have callback associated ● Two possibilities ○ Error ○ Result of the events
  20. Express ● Fast, minimal un opinionated web framework for node.js ● Important concepts ○ Application ○ Middleware ○ Router ( Type of middleware )
  21. Express stack Middleware 1 Middleware 2 Middleware 3 Request Response Response Response
  22. AngularJs ● Javascript framework for rich client development aka single page apps ● Follows MVC paradigm, where ○ Model - javascript object ○ View - html and css ○ Controller - Angular code to bind view and model ● Powerful two way data binding.
  23. Mongodb ● Document oriented NoSQL database ○ JSON style document storage ○ schema-less ● Autosharded ● Row level atomicity ● Rich documented oriented querying
  24. Our application Express REST API URLs collection in mongodb Client Chrome Plugin Client AngularJS UI
Advertisement