July 2018
Intermediate to advanced
324 pages
8h 14m
English
Since we have discussed the Mashape API configuration, let's write a code snippet to implement functionality for fetching the random quote data. Have a look at the following code snippet:
File—mashape.py:
import osimport requestsdef fetch_quote(): response = requests.get( os.environ.get('Mashape_API_Endpoint'), headers={ 'X-Mashape-Key': os.environ.get('X_Mashape_Key'), 'Accept': 'application/json' } ) if response.status_code == 200: return response.json()[0] return response.json()
As you can see, we wrote a method named fetch_quote, which is responsible for fetching the random quote data from the Mashape API. We are going to use this method for further implementation.
Now, let's write a resource API for our ...
Read now
Unlock full access