A boilerplate SDK that can be cloned to help you create a Node SDK on top of your restful API. Comes with a
Ping module to get you started.
- Handles authentication and stores the token with the SDK for retrieval. Grabs a new token when it expires.
- Modular design makes it easy to add on new modules.
- Already created unit tests and coverage metrics.
- Documentation set to go.
- The SDK comes with a placeholder name, "Foo". You will want to start off with a global find/replace in files and do a case sensitive find/replace for "Foo" and "foo" and replace them with your SDK name.
- Double check package.json was properly modified and replace the github repository and any other properties with your values.
- Revise the token class to fit your your authorization server returns when you request a token. What's included is pretty standard, so this step might be optional.
- Open up config.js and replace the
userAgentproperty with what you would like to use. Replace the endpoints with your own.
- Create a
.envfile and create any environment variables that will need to be loaded. By default,
FOO_SECRETare needed for authorization to work. For development work, a
ENVIRONMENTvariable is also supposed. See
npm ito install all dependencies and you should be good to go. If you have any package issues, you may want to run
npm i mocha istanbul jsdoc -gand install the executable packages globally.
- Fill in your readme and you're good to go!
- Sign up for a Travis CI and Coveralls accounts. Configuration files are already included, though you will need to add your token from Travis CI to
npm tests- Runs tests
npm run coverage- Runs tests and calculates code coverage metrics. Outputs to
npm run generate-docs- Generates the JSdoc documentation.
npm run coveralls
The architecure is straight forward and should be easy to follow.
├── lib │ ├── helpers │ │ ├── environment.helpers.js <-- Gets your environment. │ ├── models │ │ ├── token.model.js <-- Token model. To be used as a pattern module, but needed by thr auth module. │ ├── modules │ │ ├── auth.module.js <-- Auth module. Used to handle authorization │ │ ├── foo-api.module.js <-- Super class containing methods needed by sub-classes to call your API. All sub classes inherit this. │ │ ├── ping.module.js <-- Starter module. Extends Foo class in foo-api.module.js To be used as a pattern example. Can be deleted ├── spec │ ├── foo-api.spec.js <-- Unit tests │ ├── manual-tests.js <-- Used for Visual Studio Code debugging ├── index.js <-- entry point. Exports the top-level namespace. Add new modules to Foo object to expose them to the user ├── .config.js <-- Contains configuration info ├── .env <-- used for environment settings. ├── .jsdoc.json ├── .travis.yml ├── .coveralls.yml ├── LICENSE ├── README.MD
- Private methods and properties are prefixed with an underscore. These are methods and properties needed by your public methods, but in general aren't meant to be used with your SDK.
- Filenaming uses the Angular CLI style.
<name with dashes>.<type>.js
- Clone the repo on your local machine
npm ito install depedencies.
npm run coverageto run tests and calculate code coverage.
npm run generate-docsto generate the docs
Debugging in VS Code
The recommended editor for working on the code is Visual Studio code, which is has a debug configuration already setup.
In the specs folder, modify the file
manual-tests.js to run through the code you desire to debug. When you're ready, select the "debug" icon in the pane and click "launch program" and it will hit any breakpoints you set.