Product | Validator Services API |
---|---|
Description | Node.JS app that provides various API end points used by the IATI Validator API; also handles the validation for ad hoc data checks in user sessions on the Validator website. |
Website | https://validator.iatistandard.org |
Related | IATI/validator-web, IATI/js-validator-api |
Documentation | https://developer.iatistandard.org/ |
Technical Issues | https://github.com/IATI/validator-services/issues |
Support | https://iatistandard.org/en/guidance/get-support/ |
See OpenAPI specification postman/schemas/index.yaml
. To view locally in Swagger UI, you can use the 42crunch.vscode-openapi
VSCode extension.
-
Blob Trigger
- When file is added to blob storage container with name
ADHOC_CONTAINER
, this Function is triggered. /api/pvt/adhoc/upload
or/api/pvt/adhoc/url
are the endpoints used to add files to blob storage.
- When file is added to blob storage container with name
-
Actions
- Sends file to Validator API
- Saves validation report and metadata to
adhoc_validation
table
- nvm - nvm - Node version manager
- Node LTS
- once you've installed nvm run
nvm use
which will look at.nvmrc
for the node version, if it's not installed then it will prompt you to install it withnvm install <version>
- once you've installed nvm run
- Azure Functions Core Tools v4
- Azure CLI version 2.4 or later.
- Follow instructions for nvm/node prerequisties above
- Run
npm i
- Run
npm start
to run the function locally using the Azure Functions Core Tools
cp .env.example .env
# DB connection
PGDATABASE=<dbname>
PGHOST=<host>
PGPASSWORD=
PGPORT=5432
PGSSL=true
PGUSER=<username>@<host>
# name of adhoc azure blob container
ADHOC_CONTAINER=
# validator API url and api key
VALIDATOR_API_URL=
VALIDATOR_FUNC_KEY=
Required due to the storage binding used by this function
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "node",
"AzureWebJobsStorage": <storage_connection_string>,
"STORAGECONNECTOR": <storage_connection_string>,
"ADHOC_CONTAINER": <ADHOC_CONTAINER>
}
}
Add in:
- .env.example
- .env
/config/config.js
Import
const config = require("./config");
let myEnvVariable = config.ENV_VAR
- Set a breakpoint
- Press F5 to start the Azure Function and Attach the VSCode debugger
- Configuration is contained in
.vscode/launch.json
and.vscode/tasks.json
- Configuration is contained in
- Trigger a request that will hit your break point
- Enojy!
- To show linting inline install ESLint for VSCode
- This is done with eslint following the airbnb-base style and using Prettier. Implemented with this guide.
- If you use VSCode the formatting will happen automagically on save due to the
.vscode/settings.json
>"editor.formatOnSave": true
setting
func new --name <routename> --template "HTTP trigger" --authlevel "function"
- Install newman globally
npm i -g newman
- Start function
npm start
- Run Tests
npm test
Integration tests are written in Postman v2.1 format and run with newman
Import the integrations-tests/azure-function-node-microservice-template.postman_collection.json
into Postman and write additional tests there
https://github.com/IATI/IATI-Internal-Wiki#detailed-workflow-steps