SlideShare una empresa de Scribd logo
1 de 23
Descargar para leer sin conexión
JavaScript UI
       for REST services
Backbone, Require.js, Jasmine, HtmlUnit
     JUG #5 București @Cegeka
Ioan Eugen Stan
Partner @Axemblr
Apache James PMC member
Debianist

Connect with me on Linkedin
Disclaimer
One solution out of many. Focus on some
             best practices.
Why?
REST services are nice but we need an UI that
is:
● easy to develop against the API
● easy to test (cross-browser)
● brakes when API evolves - but informs us
    what changed
● can have continuous integration with our
    service
Tools
● Backbone - MVC for the Browser
● Require.js - modules for JS - put some order
  in that chaos !!
● Jasmine - JS BDD and unit testing
● HtmlUnit - "GUI-Less browser for Java
  programs"
● jasmine-maven-plugin - combines Jasmine,
  HtmlUnit and Requirejs into a Maven plugin
Backbone.js
● gives structure to web applications
● provides: models, collections and views
● binds view to collections/models by custom
  events
● declarative event handling

● views can be rendered detached from DOM!!
Sample Backbone Model
 Todo.Item = Backbone.Model.extend({
    defaults:function () {
      return {
         title:"",
         created:-1
      }
    }
 })
Sample Backbone View
 var TodoView = Backbone.View.extend({
    events:{
        "click .delete":"deleteTodo"
    },
    render:function () {
        this.$el.html(Table)
        return this;
    },
    deleteTodo:function (eventName) {
       this.model.delete() }
 })
Backbone conclusions
  Allows us stay away from DOM
manipulations so we can test things in
              isolation
Require.js
Is a file and module loader for JavaScript and:

● puts structure in to the web application
● fights against namespace pollution => less
  weird bugs !!
● has some nice optimization features
Require.js App File Structure
project-directory/
●  index.html
●  js/
    ○   libs/
          ■  require.js
          ■  backbone.js
          ■  jquery.js
    ○   model/ ...
    ○   view/ ...
    ○   tpl/ - templates
    ○   config.js - require.js config file
Index page with Require.js
<html>
<head> <!-- title, CSS definitions, etc--> </head>
<body>

<div id="container" class="container"></div>

<script data-main="/assets/js/config.js" src="
/assets/js/libs/require.js"></script>

</body>
</html
Jasmine
Behavior-driven development framework for
         testing JavaScript code.
Jasmine features
●   does not depend on DOM
●   has very nice semantics
●   can use Spyes to inspect/mock calls
●   comes with jQuery support
●   you can even test for events like: click, blur,
    etc.
Sample Jasmine Spec
 describe("mode/todo Todo Collection", function () {
   var collection

      beforeEach(function () {
         // initialize collection before each test case
      })

      it("loads data from the proper url", function () {
          expect(collection.length).toBe(1)
      })
 })
HtmlUnit
"GUI-Less browser for Java programs"
HtmlUnit provides:
●   support for HTTP/HTTPS
●   cookies
●   forms, clicking links,
●   most important HTTP: POST, GET, etc.
●   JavaScript

Use it when you need to test code that runs in
                the browser!
Jasmine Maven Plugin
   Test drive your JavaScript
Jasmine Maven Plugin - esentials
● built on HtmlUnit with Jasmine, + Require.js
● it helps you practice TDD/BDD as you write
  JavaScript
● it can run as part of your build with no added
  configuration on your part
● also supports CoffeScript
Jasmine Maven Plugin - config
<configuration>
 <browserVersion>FIREFOX_3</browserVersion>
              <junitXmlReportFileName>TEST-FIREFOX_3-jasmine.
xml</junitXmlReportFileName>
 <jsSrcDir>${project.basedir}/src/main/resources/assets</jsSrcDir>
              <jsTestSrcDir>${project.basedir}
/src/test/javascript/specs</jsTestSrcDir>

<specRunnerTemplate>REQUIRE_JS</specRunnerTemplate>
</configuration>
Jasmine Maven Plugin - benefits
● you can integrate with CI infrastructure
  (Jenkins)
● has multiple browser support => test your
  code against I.E. 6,7,9, Firefox, Chrome, etc.
● we can test JS models with the fixtures used
  in Java !!
Resources
● Demo : https://github.com/bucharest-
  jug/dropwizard-todo (todo-service)
● Other:
  ○   http://backbonejs.org/
  ○   http://underscorejs.org/
  ○   http://requirejs.org/
  ○   http://pivotal.github.com/jasmine/
  ○   http://htmlunit.sourceforge.net/
  ○   http://searls.github.com/jasmine-maven-plugin/
  ○   https://github.com/ieugen/brooklyn/tree/app-explore
Thanks
ieugen@apache.org

Más contenido relacionado

La actualidad más candente

System webpack-jspm
System webpack-jspmSystem webpack-jspm
System webpack-jspm
Jesse Warden
 

La actualidad más candente (20)

Packing it all: JavaScript module bundling from 2000 to now
Packing it all: JavaScript module bundling from 2000 to nowPacking it all: JavaScript module bundling from 2000 to now
Packing it all: JavaScript module bundling from 2000 to now
 
Grunt.js and Yeoman, Continous Integration
Grunt.js and Yeoman, Continous IntegrationGrunt.js and Yeoman, Continous Integration
Grunt.js and Yeoman, Continous Integration
 
JavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & BrowserifyJavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & Browserify
 
Packing for the Web with Webpack
Packing for the Web with WebpackPacking for the Web with Webpack
Packing for the Web with Webpack
 
One step in the future: CSS variables
One step in the future: CSS variablesOne step in the future: CSS variables
One step in the future: CSS variables
 
An Overview on Nuxt.js
An Overview on Nuxt.jsAn Overview on Nuxt.js
An Overview on Nuxt.js
 
Browserify
BrowserifyBrowserify
Browserify
 
Lightning Talk: Making JS better with Browserify
Lightning Talk: Making JS better with BrowserifyLightning Talk: Making JS better with Browserify
Lightning Talk: Making JS better with Browserify
 
System webpack-jspm
System webpack-jspmSystem webpack-jspm
System webpack-jspm
 
Webpack DevTalk
Webpack DevTalkWebpack DevTalk
Webpack DevTalk
 
Web Applications with AngularJS
Web Applications with AngularJSWeb Applications with AngularJS
Web Applications with AngularJS
 
Webpack
WebpackWebpack
Webpack
 
An Intro into webpack
An Intro into webpackAn Intro into webpack
An Intro into webpack
 
Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS Introdruction
 
Zk doc1
Zk doc1Zk doc1
Zk doc1
 
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST APIWordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
 
Introduction to VueJS & Vuex
Introduction to VueJS & VuexIntroduction to VueJS & Vuex
Introduction to VueJS & Vuex
 
Webpack Tutorial, Uppsala JS
Webpack Tutorial, Uppsala JSWebpack Tutorial, Uppsala JS
Webpack Tutorial, Uppsala JS
 
Require js
Require jsRequire js
Require js
 
Let's react - Meetup
Let's react - MeetupLet's react - Meetup
Let's react - Meetup
 

Similar a Javascript ui for rest services

Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
Andy Peterson
 
Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best Practices
Doris Chen
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new build
Igor Khotin
 
Javascript frameworks: Backbone.js
Javascript frameworks: Backbone.jsJavascript frameworks: Backbone.js
Javascript frameworks: Backbone.js
Soós Gábor
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 

Similar a Javascript ui for rest services (20)

Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
RequireJS
RequireJSRequireJS
RequireJS
 
Developing High Performance Web Apps
Developing High Performance Web AppsDeveloping High Performance Web Apps
Developing High Performance Web Apps
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
 
Odoo Experience 2018 - The Odoo JS Framework
Odoo Experience 2018 - The Odoo JS FrameworkOdoo Experience 2018 - The Odoo JS Framework
Odoo Experience 2018 - The Odoo JS Framework
 
Training in Android with Maven
Training in Android with MavenTraining in Android with Maven
Training in Android with Maven
 
Using RequireJS with CakePHP
Using RequireJS with CakePHPUsing RequireJS with CakePHP
Using RequireJS with CakePHP
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
 
Webpack
Webpack Webpack
Webpack
 
企业级软件的组件化和动态化开发实践
企业级软件的组件化和动态化开发实践企业级软件的组件化和动态化开发实践
企业级软件的组件化和动态化开发实践
 
Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best Practices
 
Modern Web Technologies
Modern Web TechnologiesModern Web Technologies
Modern Web Technologies
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new build
 
Javascript frameworks: Backbone.js
Javascript frameworks: Backbone.jsJavascript frameworks: Backbone.js
Javascript frameworks: Backbone.js
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJS
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
 

Más de Ioan Eugen Stan

Más de Ioan Eugen Stan (8)

Modern authentication in Sling with Openid Connect and Keycloak - Adapt.to 20...
Modern authentication in Sling with Openid Connect and Keycloak - Adapt.to 20...Modern authentication in Sling with Openid Connect and Keycloak - Adapt.to 20...
Modern authentication in Sling with Openid Connect and Keycloak - Adapt.to 20...
 
Gradle build automation tool
Gradle   build automation toolGradle   build automation tool
Gradle build automation tool
 
Modular Java applications with OSGi on Apache Karaf
Modular Java applications with OSGi on Apache KarafModular Java applications with OSGi on Apache Karaf
Modular Java applications with OSGi on Apache Karaf
 
Hands on continouous delivery, I TAKE 2014
Hands on continouous delivery, I TAKE 2014Hands on continouous delivery, I TAKE 2014
Hands on continouous delivery, I TAKE 2014
 
2013 java2 days web apps - a different angle
2013 java2 days web apps - a different angle2013 java2 days web apps - a different angle
2013 java2 days web apps - a different angle
 
Enterprise Integration Patterns with Apache Camel
Enterprise Integration Patterns with Apache CamelEnterprise Integration Patterns with Apache Camel
Enterprise Integration Patterns with Apache Camel
 
Bjug Spring Custom Namespaces by Vlad Untu
Bjug Spring Custom Namespaces by Vlad UntuBjug Spring Custom Namespaces by Vlad Untu
Bjug Spring Custom Namespaces by Vlad Untu
 
Apache james more than emails in the cloud
Apache james  more than emails in the cloudApache james  more than emails in the cloud
Apache james more than emails in the cloud
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Javascript ui for rest services

  • 1. JavaScript UI for REST services Backbone, Require.js, Jasmine, HtmlUnit JUG #5 București @Cegeka
  • 2. Ioan Eugen Stan Partner @Axemblr Apache James PMC member Debianist Connect with me on Linkedin
  • 3. Disclaimer One solution out of many. Focus on some best practices.
  • 4. Why? REST services are nice but we need an UI that is: ● easy to develop against the API ● easy to test (cross-browser) ● brakes when API evolves - but informs us what changed ● can have continuous integration with our service
  • 5. Tools ● Backbone - MVC for the Browser ● Require.js - modules for JS - put some order in that chaos !! ● Jasmine - JS BDD and unit testing ● HtmlUnit - "GUI-Less browser for Java programs" ● jasmine-maven-plugin - combines Jasmine, HtmlUnit and Requirejs into a Maven plugin
  • 6. Backbone.js ● gives structure to web applications ● provides: models, collections and views ● binds view to collections/models by custom events ● declarative event handling ● views can be rendered detached from DOM!!
  • 7. Sample Backbone Model Todo.Item = Backbone.Model.extend({ defaults:function () { return { title:"", created:-1 } } })
  • 8. Sample Backbone View var TodoView = Backbone.View.extend({ events:{ "click .delete":"deleteTodo" }, render:function () { this.$el.html(Table) return this; }, deleteTodo:function (eventName) { this.model.delete() } })
  • 9. Backbone conclusions Allows us stay away from DOM manipulations so we can test things in isolation
  • 10. Require.js Is a file and module loader for JavaScript and: ● puts structure in to the web application ● fights against namespace pollution => less weird bugs !! ● has some nice optimization features
  • 11. Require.js App File Structure project-directory/ ● index.html ● js/ ○ libs/ ■ require.js ■ backbone.js ■ jquery.js ○ model/ ... ○ view/ ... ○ tpl/ - templates ○ config.js - require.js config file
  • 12. Index page with Require.js <html> <head> <!-- title, CSS definitions, etc--> </head> <body> <div id="container" class="container"></div> <script data-main="/assets/js/config.js" src=" /assets/js/libs/require.js"></script> </body> </html
  • 13. Jasmine Behavior-driven development framework for testing JavaScript code.
  • 14. Jasmine features ● does not depend on DOM ● has very nice semantics ● can use Spyes to inspect/mock calls ● comes with jQuery support ● you can even test for events like: click, blur, etc.
  • 15. Sample Jasmine Spec describe("mode/todo Todo Collection", function () { var collection beforeEach(function () { // initialize collection before each test case }) it("loads data from the proper url", function () { expect(collection.length).toBe(1) }) })
  • 17. HtmlUnit provides: ● support for HTTP/HTTPS ● cookies ● forms, clicking links, ● most important HTTP: POST, GET, etc. ● JavaScript Use it when you need to test code that runs in the browser!
  • 18. Jasmine Maven Plugin Test drive your JavaScript
  • 19. Jasmine Maven Plugin - esentials ● built on HtmlUnit with Jasmine, + Require.js ● it helps you practice TDD/BDD as you write JavaScript ● it can run as part of your build with no added configuration on your part ● also supports CoffeScript
  • 20. Jasmine Maven Plugin - config <configuration> <browserVersion>FIREFOX_3</browserVersion> <junitXmlReportFileName>TEST-FIREFOX_3-jasmine. xml</junitXmlReportFileName> <jsSrcDir>${project.basedir}/src/main/resources/assets</jsSrcDir> <jsTestSrcDir>${project.basedir} /src/test/javascript/specs</jsTestSrcDir> <specRunnerTemplate>REQUIRE_JS</specRunnerTemplate> </configuration>
  • 21. Jasmine Maven Plugin - benefits ● you can integrate with CI infrastructure (Jenkins) ● has multiple browser support => test your code against I.E. 6,7,9, Firefox, Chrome, etc. ● we can test JS models with the fixtures used in Java !!
  • 22. Resources ● Demo : https://github.com/bucharest- jug/dropwizard-todo (todo-service) ● Other: ○ http://backbonejs.org/ ○ http://underscorejs.org/ ○ http://requirejs.org/ ○ http://pivotal.github.com/jasmine/ ○ http://htmlunit.sourceforge.net/ ○ http://searls.github.com/jasmine-maven-plugin/ ○ https://github.com/ieugen/brooklyn/tree/app-explore