Rock API Quickstart

Here you will learn how to use the Rock API to access information about rocks. This tutorial will go over the following methods.

Python

This method will use the requests library.

First, install requests:

pip install requests

Now, use the following code in your Python file:

import requests

url = "rockapi.apiworks.tech/rock/random"

payload={}
headers = {}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

Let’s go over what this code does.

  1. We import the requests library.

  2. We define the API URL.

  3. We define an empty dictionary for both payload and headers, as they are not required to use this request.

  4. The requests library creates a GET request with url, headers, and data parameters.

  5. We print the response.

NodeJS

This method will use the requests library.

First, install requests:

npm install request

Now, use the following code in your NodeJS file:

var request = require('request');
var options = {
  'method': 'GET',
  'url': 'rockapi.apiworks.tech/rock/random',
  'headers': {
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

Let’s go over what this code does.

  1. We import the requests library.

  2. We define the API URL and method.

  3. Run the request function with the options dictionary.

  4. We print the response or throw an error if one occurs.