Challenge: Building APIs
Practice implementing a working version of the Credit-Check API.
We'll cover the following
Exercise
In this challenge, you finally get to code the API. That means you’ll be using the design assets along with Node.js and the DARRT library to implement a working version of the Credit-Check API.
- First, copy the DARRT library into your Node.js project.
- Next, use information from the ALPS document and WSD diagram to update the DARRT library files.
- Finally, fire up the completed Credit-Check API and run the validator script to ensure the service at least supports the intended happy-path workflow.
Implement your API
You’ll need to use design documents from the project’s assets
folder as guides while you implement the API. You can rely on the resource diagram (credit-check-http.png
) and ALPS profile (credit-check-alps.xml
or credit-check-alps.json
) to help you fill in the data.js
, actions.js
, resources.js
, and transitions.js
files.
For this challenge, you won’t need to update the representations.js
file because it’s already been set up for all the output formats needed for this project. You’ll also notice that the data.js
file has been set up with the common basic data properties id
, status
, and dateCreated
, dateUpdated
. You’ll only need to add the fields defined by the credit-check
design. The actions.js
, resources.js
, and transitions.js
files will need to be updated to match your design specifications.
Validate your API’s workflow
Finally, after updating the DARRT files, your API should be ready for validation. For this challenge, you can run the hp-credit-check.sh
script provided in the API folder. To run this, execute the sh tests/hp-credit-check.sh
command. Then, match your output with the output provided in the cat tests/hp-credit-check-output.txt
text file in the same folder.
Terminal
As usual, practice the tasks given above in the terminal below. The DARRT library has been already copied to the API folder.
Note: Don’t forget to execute
npm run dev
in the second terminal. Make sure you set the path by executingcd usercode/credit-check
before doing so. You can click the “+
” sign to open the second terminal.
Get hands-on with 1400+ tech skills courses.