Solution: API Calls with curl

Let's try to make API calls with curl to save responses to the disk.

We'll cover the following

Solution

The challenge was to use the curl command-line tool to pull a series of responses from three related services (Company, Account, and Activity) and save them to the disk for later reference.

  1. First, move to the folder called services.

  2. Modify the API name in line-2 of index.js file. Currently, we have written ./company-home. You can update it to any filename that is provided in the same services folder.

  3. Click on “Run” button for that particular API.

  4. Click on “+” icon to add another terminal.

  5. Execute the following command in new terminal to save the API response in a new file company-home.json.

curl https://ed-5556326259752960.educative.run > company-home.json

Note: Use your own (URL generated after running the code is different for each learner on educative platform) API URL in above command. The output is shown below:

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   399  100   399    0     0   1291      0 --:--:-- --:--:-- --:--:--  1291

The resulting data saved in the company-home.json file looks like this: {"home" : {"name":"company", "rel" : "collection", "href":"/company/list/"}}

Note: You can modify file name for each API call.

  1. To verify, execute ls command. You’ll see the list of files that have been created and saved.

  2. To see the file’s content (API response), execute cat file-name.

Repeat the same process for all the provided API calls.

This challenge has a total of seven URLs. When we’re done calling all of them, we should have a list of files that looks like this:

account-list.json 
account-record.json 
activity-list.json 
activity-record.json 
company-home.json 
company-list.json 
company-record.json

You can see the list of created documents by executing the ls command.

Get hands-on with 1200+ tech skills courses.