We can easily save an API response into a file by just using the terminal in our system. We will use a fake API that returns a JSON file.
Let’s first get the response using curl.
curl https://api.mocki.io/v1/b043df5a
output:
[{"city":"Stockholm","name":"Lennart Johansson"},{"city":"London","name":"Karl Eriksson"},{"city":"Helsinki","name":"Pekka Hartikainen"},{"city":"Berlin","name":"Mia Svensson"}]
Now, If we want to save the response into a file, we can do it easily by running the following
curl -o file.txt https://api.mocki.io/v1/b043df5a
Running the above, you should have a fille created with the name file.txt.