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.jsand 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.jsfile 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.jsfile. For example, create a function calledsubtractthat takes two numbers and returns the difference. Use comments and show how Copilot can generate the function. -
The
testfolder 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.jsfile 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-utilswith// 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.jsfor the sample swagger-doc comment for the/addendpoint inindex.js. Copy and paste that sample comment into theindex.jsfile just above the/addendpoint. 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/** @swaggerand Copilot will do the rest. The Swagger Docs can be found at the/api-docsendpoint. Remember to update the server url inswagger-config.jsto the url of your codespace if applicable as Swagger will becurling the server directly.