REST API explained with examples for Power BI developers
Mateusz Sawicki
I'm not another AI expert but I'm pretty good at data engineering ???
Introduction?
If you've ever had to deal with web services, it's highly likely you've come across the term REST API. APIs (Application Programming Interfaces) are like the pipelines for different software applications to communicate and share data with each other. When talking about web services, we often refer to REST APIs - a standard style of API design that is widely adopted due to its simplicity and scalability. In this article, I will do my best to make you familiar with REST APIs, taking our time to walk you through all its essentials. Examples will be drawn from Azure and Power BI, two popular services by Microsoft that leverage REST APIs extensively. I’ve chosen them because I use them in my everyday tasks. Leveraging those tools saves me many hours of manual work and lots of component I build are reusable for future project. So, good understanding of REST APIs is a ticket to the world of easier and more efficient job!?
What is an API??
Before we deep dive into REST APIs, we need to thoroughly understand what API is. This acronym stands for Application Programming Interface, can be thought of as a set of rules that allows different software applications to communicate with each other. Essentially, it's like a menu in a restaurant. The menu provides a list of dishes you can order, along with a description of each dish. When you specify what menu items you want, the kitchen does the work and provides you with some finished dishes. You don't know exactly how the kitchen prepares that food, and you don't really need to.?
Similarly, an API lists a bunch of operations that a programmer can use, along with a description of what each operation does. The programmer doesn't need to understand how the operations are implemented - they just need to know what it does and what they need to provide to use it.?
For instance, when you use an application on your mobile phone, the app connects to the Internet and sends data to a server. The server then retrieves that data, interprets it, performs the necessary actions, and sends it back to your phone. The application then interprets that data and presents you with the information you wanted in a readable way. This is what an API is all about.?
Why Do We Need APIs??
APIs, whether they're SOAP, REST, or any other type, are crucial in enabling software applications to interact, exchange data, and perform tasks seamlessly. They act as an intermediary between different software systems, allowing them to communicate and understand each other.?
For instance, consider a travel booking website. This website might use APIs to interact with airline companies' systems, hotel systems, and other travel service systems. When you search for a flight on the booking website, it sends a request to the airline's system via its API, asking for information on available flights. The airline's system sends back a response, which the booking website then presents to you. This process happens in real time and is made possible by APIs.?
In summary, APIs enable different software systems to interact in a standardized way, making it possible to integrate different systems and create complex, feature-rich applications. They hide the complexity of these systems, allowing developers to use their functionality without needing to understand all the details of how they work.?
SOAP API?
In previous paragraph I mentioned SOAP API, let’s explain what it is. Before the introduction of REST APIs, there was another type of web service communication protocol known as SOAP (Simple Object Access Protocol). SOAP is a standard protocol defined by the World Wide Web Consortium (W3C) that allows for the exchange of structured information in web services using XML. SOAP can operate over any protocol, such as HTTP, SMTP or even FTP, and is highly extensible and versatile, which allows it to be utilized in a wide range of applications.?
However, SOAP can be quite complex to use, and its heavy use of XML can lead to large, verbose messages. This has led many developers to adopt the simpler, more lightweight REST architecture for their APIs.?
Here are a few places you might still encounter SOAP APIs:?
While the trend in recent years has been towards RESTful APIs due to their simplicity and ease of use, SOAP remains a viable and important technology, especially in sectors where its particular strengths are required. As always, the choice between SOAP and REST (or indeed other technologies) will depend on the specific requirements of the project at hand.?
What is a REST API??
REST, which stands for Representational State Transfer, is a set of principles for designing networked applications. APIs following these principles are referred to as RESTful APIs or simply REST APIs. Essentially, a REST API provides a structured way for applications to interact with each other over the internet.?
To simplify this, imagine you want to request a movie from a video streaming service like Netflix. You choose a movie, and Netflix's server gets the information about the movie, such as its title, description, and the actual video file. This process involves sending requests from the Netflix application on your device to the Netflix server, which then sends back the necessary data. This communication happens through an API - in this case, a REST API.?
Key Concepts in REST API?
Now, let's understand some key REST concepts.?
Resources?
In REST APIs, a "resource" refers to any object that can be accessed. For instance, in Azure, a virtual machine or a database could be considered resources. Similarly, in Power BI, a report or dashboard can be seen as a resource.?
领英推荐
Endpoints?
Each resource is identified by a specific URL, known as an "endpoint". For instance, in Power BI, an endpoint could look something like this: https://api.powerbi.com/v1.0/myorg/reports/{reportId}, where {reportId} is replaced with the actual ID of a report. This endpoint allows you to interact with the specific report identified by the {reportId}.?
What is HTTP?
HTTP, which stands for Hypertext Transfer Protocol, is the foundational protocol used for transferring data over the internet. It's essentially the language that web browsers (like Google Chrome or Firefox) use to communicate with web servers, which host websites and other data.?
When you type a URL into your web browser, it sends an HTTP request to the web server that hosts the corresponding website. The server then sends back an HTTP response, containing the content of the website which your browser then displays.?
HTTP is a crucial part of the web as we know it, allowing for the communication that forms the basis of web browsing. It's a stateless protocol, which means each request is treated independently and doesn't retain information from previous requests. This simplicity is one of the reasons for the widespread adoption of HTTP.?
HTTP Methods?
When interacting with a REST API, we use standard HTTP methods. These methods define what action we intend to perform:?
For example, in Power BI, you could use a GET request to list of reports in a given workspace, a POST request to refresh dataset, a PUT request to update a file to Azure Storage Account, or a DELETE request to remove a resource in Azure subscription.?
Status Codes?
HTTP status codes are three-digit numbers returned by servers to indicate the status of a web element or to communicate how a browser should proceed. These codes are divided into five classes, each of which signifies a category of response.?
It's important to note that although these conventions are widely adopted, they are not strictly enforced. Any server can return any code, so each application should be prepared to handle any status code that comes its way.?
Real-Life Examples of REST APIs in Azure and Power BI?
Now, let's look at some real-life examples of how REST APIs are used in Azure and Power BI.?
Remember, when working with the Power BI REST API, you'll need to handle authentication. This typically involves registering an application in the Azure portal, then using the application's credentials to obtain an access token from Azure's OAuth 2.0 endpoint.?
These examples show just a few ways that the Power BI REST API can help streamline your developer’s life. Depending on your specific needs, there may be many other ways to leverage the API to improve efficiency and effectiveness. ?
Conclusion?
In the world of web services, REST APIs play a vital role in enabling different software applications to communicate and share data with each other. Azure and Power BI are just two of the countless services that use REST APIs extensively, providing developers a standard, structured, and efficient way of interacting with their resources.?
By now, you should have a basic understanding of REST APIs and how they function. Remember, every REST API revolves around the concepts of resources, endpoints, HTTP methods, and status codes. Understanding these fundamentals is the key to leveraging the power of REST APIs in your web applications. From business intelligence developer perspective, leveraging Power BI REST API can by real game changer for your day-to-day development.?
?
?? Senior BI Analyst | ?? Power BI & SQL Expert | ?? Automation & Cost Optimization for Impactful Decisions
1 年Mateusz Sawicki I really like your article. It's very clean and easy to understand, specially for people without IT background like me. You gave some examples of using the API in power bi, you have any link for this kind of examples?
Does anyone have a walkthrough on how to allow the use of the Power BI REST API? . Many methods out there of various types, and Postman didn't handle the authentication process without manual intervention when testing it Thanks in advance
Thank You for this post Mateusz! Very informatice and easy-digest written !
AI Customer Success Manager
1 年This article is a game-changer! As someone transitioning into BI, this comprehensive explanation of Power BI REST API is valuable.
Lead technical consultant | DataBrothers co-founder | Microsoft Fabric & Power BI MVP
1 年This is great and nicely explained! Can I reference your article in my article about extracting data from API by Power Query?