GET request from a REST-Service

A REST-Service is one of the modern ways web services communicate with each other, meaning how they transmit data to each other. Because of the prevalence of REST-Services on the web the problem described is a very common one nowadays and one of the most used communication ways is via a JSON file. So how do you GET and save a JSON file which is available on a REST-Service.
1 answer

Solution in Python with Requests

This article solves the following challenge: 

GET request from a REST-Service

To get and save the JSON data in Python there are many libraries we could use, I'm showing you how to do it with one of the more common ones "Requests". It works as follows:
import requests
jsondata = requests.get("http://exampleurl.com/get").json()
These two lines are actually a fully working python program which extracts the data on the example URL via "get()" and forms it into a json via "json()". The result gets saved into the "jsondata" variable.

Evaluate complexity of present statement:

Select ratingCancelGuessingPassing knowledgeKnowledgeableExpert

Your rating: None Average: 2 (1 vote)

Taggings: