In this challenge, the task was to use the design assets to implement a working API service using Node.js and the DARRT library. The three key tasks are these:

  1. Install the DARRT library into the Node.js project.
  2. Update the DARRT files (data, action, resources, representations, and transitions).
  3. Once the API is completed, run a happy-path validator script.

Installing the DARRT Library

Execute the following command:

npm run dev

This should start up the API project and output something that looks like this:

> credit-check@1.0.0 dev /credit-check
> nodemon index

[nodemon] 2.0.18
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index index.js`
listening on port 8181!

Note: Don’t forget to execute npm run dev in the second terminal. Make sure you set the path by executing cd usercode/credit-check before doing so. Click the “+” sign to open the second terminal.

Now test the API service by typing the following on the command line in the first terminal:

curl localhost:8181/ -H "accept:application/json" | jq "."

This should produce an output that looks like the one below:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   278  100   278    0     0  10296      0 --:--:-- --:--:-- --:--:-- 10296
{
  "home": [
    {
      "id": "list",
      "name": "credit-check",
      "rel": "collection credit",
      "href": "http://localhost:8181/list/"
    }
  ]
}

Now that we have the initial project up and running, we can start to update the DARRT files to implement our Credit-Check API.

Updating DARRT files

We need to update (or at least confirm the contents of) the data.js, actions.js, resources.js, representations.js, and transitions.js files provided in the darrt folder. Each of these files needs to reflect the details of our Credit-Check API design assets provided in the assets folder.

Note: We’ve provided a complete solution with updated files (data.js, actions.js, resources.js, representations.js, and transitions.js) at the end of this lesson.

The data.js file

To start, open the data.js file and enter the data property details from our bigco-credit-check-api-1.0.0-swagger.yaml document. When we’re done, it should look like this:

Get hands-on with 1200+ tech skills courses.