blog image
pip install notebook

jupyter notebook

Note: You can also use Jupyter Lab or Google Colab instead of Jupyter Notebook.

 

 

Crul

curl -i -X GET "https://api.coindesk.com/v1/bpi/currentprice.json"

response as

HTTP/2 200 
content-type: application/json; charset=utf-8
content-length: 675
date: Thu, 18 Jul 2024 17:29:01 GMT
access-control-expose-headers: WWW-Authenticate,Server-Authorization
cache-control: max-age=30, must-revalidate, public
accept-ranges: bytes
vary: origin
x-cache: Hit from cloudfront
via: 1.1 b097aefce5c96f6d140009a88452ea4a.cloudfront.net (CloudFront)
x-amz-cf-pop: DEL54-P3
x-amz-cf-id: P9QBChfTswjzfQY2bEC1YpsPCNsK9g1I2GhgWxREzZVfNzVnXVykBQ==
age: 23

{"time":{"updated":"Jul 18, 2024 17:29:00 UTC","updatedISO":"2024-07-18T17:29:00+00:00","updateduk":"Jul 18, 2024 at 18:29 BST"},"disclaimer":"This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org","chartName":"Bitcoin","bpi":{"USD":{"code":"USD","symbol":"$","rate":"63,828.452","description":"United States Dollar","rate_float":63828.4522},"GBP":{"code":"GBP","symbol":"£","rate":"49,205.609","description":"British Pound Sterling","rate_float":49205.6091},"EUR":{"code":"EUR","symbol":"€","rate":"58,471.33","description":"Euro","rate_float":58471.3302}}}

 

 

cURL a command line utility developed almost 25 years ago, its main function is to fetch the response from a URL.Using the flag ‘ i ’ with cURL includes protocol response headers in the output, and ‘ X ’ allows us to define the method used, in this case “ GET ”.

And you can see, the first part of the response above are the headers while the second part is the content. Headers are useful in understanding the behaviour of the endpoint.


The first line that says “ HTTP/2 200 O K ” is called a response status code . A “ 200 OK ” response code means your request was valid and it was successfully responded to. If you change anything in the endpoint URL and try again, you
will get an “ HTTP/1.1 404 Not Foun d ” error meaning your request couldn’t be processed by the server.

 

The content part of the response in curly braces { } follows a standard format called JSON that is used to store and transmit data to and from the endpoint. Inthis example, the API responds by sending the price of Bitcoin in USD , GBP , and EUR along with several other important information such as timestamp, descriptions, etc.

 

 

Json

 

 

 

 

Introduction to Web API

 

 

Python & Working with APIs

Interacting with APIs using cURL and other utilities are fun, but in building applications and most other use cases they are too cumbersome.In such cases, modern programming languages such as Python , Go , Rust , C# ,Ruby , etc are used.

 

import requests
URL = "https://api.coindesk.com/v1/bpi/currentprice.json"
response = requests.get(URL)
data = json.loads(response.content.decode( "utf-8" ))
print(data)

 

 


About author

author image

Amrit Panta

Python developer, content writer


You may also like


3 Comments

Amanda Martines 5 days ago

Exercitation photo booth stumptown tote bag Banksy, elit small batch freegan sed. Craft beer elit seitan exercitation, photo booth et 8-bit kale chips proident chillwave deep v laborum. Aliquip veniam delectus, Marfa eiusmod Pinterest in do umami readymade swag. Selfies iPhone Kickstarter, drinking vinegar jean.

Reply

Baltej Singh 5 days ago

Drinking vinegar stumptown yr pop-up artisan sunt. Deep v cliche lomo biodiesel Neutra selfies. Shorts fixie consequat flexitarian four loko tempor duis single-origin coffee. Banksy, elit small.

Reply

Marie Johnson 5 days ago

Kickstarter seitan retro. Drinking vinegar stumptown yr pop-up artisan sunt. Deep v cliche lomo biodiesel Neutra selfies. Shorts fixie consequat flexitarian four loko tempor duis single-origin coffee. Banksy, elit small.

Reply

Leave a Reply

Scroll to Top