API to get student data.. API definition is contained in the OpenAPI specification.
Install Node.js from nodejs.org.
Generate a self signed certificate with OpenSSL:
$ openssl req -newkey rsa:2048 -new -nodes -keyout key.pem -out csr.pem $ openssl x509 -req -days 365 -in csr.pem -signkey key.pem -out server.crt
Document API design in openapi.yaml. Please keep in mind that openapi documentation is mainly for the client's view. Directly implement the feature in the API if there is any difference between what the client should expect and what our server should provide.
Copy config/default-example.yaml to
config/default.yaml. Modify as necessary, being careful to avoid committing sensitive data. If you want to configure application through custom environment variables, copy config/custom-environment-variables-example.yaml as
config/custom-environment-variables.yamland map the environment variable names into your configuration structure.
Environment variables: Sensitive data and data that changes per environment have been moved into environment variables. Below is a list of the variables along with a definition:
Environment variable Description
The port used by the API.
The port used by the ADMIN endpoint.
The HTTP Basic username used to authenticate API calls.
The HTTP Basic password used to authenticate API calls.
$ npm install
Run the application:
# Build and run the app and watch for changes using nodemon $ npm run dev # Run the app without building $ npm start
Run ESLint to check the code:
# Using gulp $ gulp lint # Using npm $ npm run lint
Run unit tests:
# Using gulp $ gulp test # Using npm $ npm test
Run the nyc tool against the unit tests:
# Using npm $ npm run coverage
After task is run, a more detailed test coverage report will be available by opening
./coverage/lcov-report/index.html in your browser.
This API is configured to use Flow static type checking.
Check flow types:
# Using gulp $ gulp typecheck # Using npm $ npm run typecheck
dist/. Source maps are also generated in the same directory. These contain references to the original source code for debugging purposes.
Babel allows for newer ECMAScript syntax such as
export from ES6. It also allows Babel plugins to be used.
Compilation is done by the
babel gulp task. This is handled automatically by other tasks but can be manually invoked:
# Using gulp $ gulp babel # Using npm $ npm run babel
proxyquireis included but only the path given by the first argument to this function will resolve correctly. The keys for each dependency path in the second argument must be relative paths.
Clone the skeleton:
$ git clone --origin skeleton firstname.lastname@example.org:osu-mist/express-api-skeleton.git <my-api>
Rename project by modifying package.json.
We use express-openapi to generate API by inheriting openapi.yaml. Create path handlers and put them into corresponding directories. For example:
Copy src/api/v1/serializers/pets-serializer.js to
src/api/v1/serializers/<resources>-serializer.jsand modify as necessary:
$ cp src/api/v1/serializers/pets-serializer.js src/api/v1/serializers/<resources>-serializer.js
Add the skeleton as a remote:
$ git remote add skeleton email@example.com:osu-mist/express-api-skeleton.git
Fetch updates from the skeleton:
$ git fetch skeleton
Merge the skeleton into your codebase:
$ git checkout feature/CO-1234-branch $ git merge skeleton/master $ git commit -v
The following instructions show you how to connect the API to an Oracle database.
dataSources/oracledbsection in the
/config/default.yamlto be like:
dataSources: dataSources: ['oracledb'] oracledb: connectString: 'DB_URL' user: 'DB_USER' password: 'DB_PASSWD' poolMin: 4 poolMax: 4 poolIncrement: 0:
Options for database configuration:
The minimum number of connections a connection pool maintains, even when there is no activity to the target database.
The maximum number of connections that can be open in the connection pool.
The number of connections that are opened whenever a connection request exceeds the number of currently open connections.
Note: To avoid
ORA-02396: exceeded maximum idle timeand prevent deadlocks, the best practice is to keep
poolMinthe same as
poolMax. Also, ensure increasing the number of worker threads available to node-oracledb. The thread pool size should be at least equal to the maximum number of connections and less than 128.
If the SQL codes/queries contain intellectual property like Banner table names, put them into
src/api/v1/db/oracledb/contribfolder and use git-submodule to manage submodules:
Add the given repository as a submodule at
$ git submodule add <contrib_repo_git_url> src/api/v1/db/oracledb/contrib
Fetch the submodule from the contrib repository:
$ git submodule update --init
Copy src/api/v1/db/oracledb/pets-dao-example.js to
src/api/v1/db/oracledb/<resources>-dao.jsand modify as necessary:
$ cp src/api/v1/db/oracledb/pets-dao-example.js src/api/v1/db/oracledb/<resources>-dao.js
Make sure to use the correct path for the new DAO file at path handlers files:
import petsDao from '../db/oracledb/<resources>-dao';