us-states-ref
v1.1.0
Published
Service, convenience Express endpoints for getting misc data on US states, e.g. addresses, license formats, etc.
Downloads
6
Readme
us-states-ref
Quick reference of info related to U.S. states, e.g. sample addresses, driver's license formats, etc.
Exposes service for use in code, Express router for convenient GET endpoints, e.g. to hit with your testing scripts/other personal work.
Pre-req's
Node 4.6.0
Setup
Copy or clone project to computer.
Install the dependencies listed in package.json, e.g. in the command prompt, nav to the us-states-ref folder and
npm install
After that's done, stay in the same folder and run
npm test
. If the tests pass, you're all set!See the apiController for mountable endpoints on an Express app.
Example usage
Using the service in code
var StateService = require('../services/StateService');
var stateService = new StateService();
console.log(stateService.getAllStates());
Mounting endpoints to an existing Express app
var express = require('express');
var apiController = require('us-states-ref').usStatesExpressRouter;
// app.use(rootPath, expressRouter)
app.use('/usstates', apiController)
Test with a GET request to /usstates/api/v1/states
Endpoint client
See an example at us-states-ref-client.
Notes for users
Drivers license format source - the Internet... your mileage may vary.
Wishlist
Sample addresses for all states, which will pass the remaining failing jasmine specs.
Extra endpoints for finer grained data - see apiController for ideas.
Get random sample addresses from an external source?
Project 20/20
The Express router makes it trivial to add endpoints onto an existing Express app. Some similarity to EARs/WARs on a Java web server.
Jasmine is easy to pick up, many concepts also transferable from JUnit/Spock. Simple enough to set up test cases running through data-driven scenarios.
Publishing packages to npm and using them in different projects (via inclusion in a package.json) is a smooth process. These service + Express router packages might be handy for a Node/Express microservices server. Time'll tell...
Node's require can read in a json file and transform for js objects. Painless but be aware - it's a synchronous/blocking operation.