How barchart/barchart-ondemand-client-js works
Project type and purpose
• This is a zero-dependency JavaScript client library (“barchart-ondemand-client-js”) that wraps HTTP/JSONP calls to the Barchart OnDemand REST APIs.
• Its main use case is to be included in any web page or web app to fetch market data (quotes, history, news, etc.) via simple method calls.
File structure
• Top-level files:
• Gruntfile.js: build tasks (concatenation, minification, test runner).
• bower.json & package.json: metadata, dependency management.
• README.md: usage and API reference.
• dist/: prebuilt bundle (browser-ready JS).
• src/ondemand-client.js: the single source module implementing the client API.
• tests/: Jasmine/BrowseRunner specs (OnDemandClientSpec.js) plus an index.html to run them in a browser.
README for additional insights
• The README lists all supported API methods (getQuote, getHistory, getNews, etc.).
• Example shows how the client:
a. Loads the dist script in an HTML page.
b. Instantiates OnDemandClient.
c. Sets an API key and JSONP mode.
d. Calls a method, passes callback, receives data.
a. Main components
1. Developer Environment
• src/ondemand-client.js
• Grunt build process
• tests (Jasmine runner)
2. Distribution
• dist/barchart-ondemand-client-js.js (minified bundle)
3. Consumer Application
• HTML/JS that embeds the dist bundle
• Instantiates OnDemandClient API
4. External System
• Barchart OnDemand API servers (REST endpoints)
b. Relationships & Data Flow
1. Developer writes/edits src → triggers Grunt → produces dist.
2. Tests run against src or dist via tests/index.html → pass/fail feedback.
3. Consumer app includes dist → invokes OnDemandClient methods → HTTP/JSONP requests → OnDemand API → responses → callbacks in app.
c. Architectural patterns & principles
• Single-module UMD wrapper (works in browser/node).
• Build pipeline: concatenation, minification, test automation.
• Callback-oriented async design (JSONP or XHR).
d. Key technologies
• JavaScript (UMD)
• Grunt (task runner: build, test)
• Jasmine (testing)
• Bower/NPM (package management)
• HTTP/JSONP transport
Detail
• That tests can run directly against src or bundled code.
• Configuration files (package.json, bower.json) feeding into the Build step.