Testing and Prototyping for REST API Data Ingestion with JSONPlaceholder
- By : Mydatahack
- Category : Data Engineering, Tools and Utilities
- Tags: Data Ingestion, JSONPlaceholder, Prototyping, Python, REST API, Testing
JSONPlaceholder is a web service that offers REST API endpoints for example JSON data. If you needs to experiment with REST API quickly, this is a really great tool that you can use. It supports all the HTTP verbs. As for testing and prototyping REST API data ingestion, you can get 6 different JSON data that you can play with.
I created a Python function where you can obtain all the data by changing the resource name. The function uses the request module. Using json() on the response object can converts it into a Python dictionary. In a nutshell, the function returns a dictionary object from the GET request.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | def json_ph_api(resource): '''Get example json data from jsonplaceholder.typicode.com. Returns Python dictionary object''' json_data = None endpoint = 'https://jsonplaceholder.typicode.com/{}'.format(resource) print('Target endpoint is {}'.format(endpoint)) r = requests.get(endpoint) if r.status_code == 200: print('API Call Successful') # data returned with r.json() is a dictionary object json_data = r.json() else: print('API call failed with status code: {}'.format(r.status_code)) return json_data |
Once you get the data, you can transform and load it into databases to create your own data ingestion code.
Pretty cool.