This demo contins a Node Express API that performs math operations. The API is tested with Mocha/Chai. New endpoints and tests are generated with Copilot.
- Run the app using
npm start
, the app will be available athttp://localhost:3000
- Show how the api works by hitting the endpoint
http://localhost:3000/add?a=1&b=b
. The paths are defined inindex.js
and the logic is defined in the directorymath-utils.js
.
Copilot Demo
-
Show how Copilot can generate new endpoints and tests for the API.
-
Create a comment in the
index.js
file that says for example// add endpoint for subtracting two numbers
. You will see Copilot generate the path call the appropriate logic for the endpoint. -
Create an associated logic file in the
math-utils.js
file. For example, create a function calledsubtract
that takes two numbers and returns the difference. Use comments and show how Copilot can generate the function. -
The
test
folder contains a Mocha/Chai test suite. We will show how Copilot can generate new tests for the API. Create a comment in thetest/test_math_utils.js
file or start to write "describe" to generate the test cases. An example looks like:describe('math_utils_add', () => { it('should add two numbers', () => { expect(math_utils_add(1, 2)).to.equal('3'); }); });
-
Show how Copilot can do other miscellaneous asks. For example you can ask Copilot to validate the inputs to the functions in
math-utils
with// validate that both a and b are numbers
. Copilot will generate the code to validate the inputs. -
Generate Swagger Documentation for the API. See the comment at the bottom of
swagger-config.js
for the sample swagger-doc comment for the/add
endpoint inindex.js
. Copy and paste that sample comment into theindex.js
file just above the/add
endpoint. Now you can best utilize Copilot to generate @swagger docs for the rest of the endpoints. Copilot will use the intial example as a template for the rest. Simply start typing/** @swagger
and Copilot will do the rest. The Swagger Docs can be found at the/api-docs
endpoint. Remember to update the server url inswagger-config.js
to the url of your codespace if applicable as Swagger will becurl
ing the server directly.