Blog Post

Azure SQL Blog
2 MIN READ

Azure SQL Database External REST Endpoints Integration Public Preview

damauri's avatar
damauri
Icon for Microsoft rankMicrosoft
Nov 16, 2022

 

The ability to call a REST endpoint natively from Azure SQL Database, which was made available via an Early Adopter Preview in May, is now moving to Public Preview. I’m extremely happy that as of today the new system stored procedure sp_invoke_external_rest_endpoint is available to everyone, automatically and transparently: you can use it right away, from any Azure SQL Database that you may already have or that you’ll create in future.

With sp_invoke_external_rest_endpoint you can call a REST endpoint, like an Azure Function, for example, with just a line of code:

 

declare @ret as int, @response as nvarchar(max);

exec @ret = sp_invoke_external_rest_endpoint 
	@method = 'GET',
	@url = 'https://my-function.azurewebsites.net/api/say?message=hello world',
	@response = @response output;
	
select @ret as ReturnCode, @response as Response;

Here’s a screenshot of the result of calling an Azure Function that provides information about local restaurants. The screenshot also shows that you can also query using GraphQL, if that is supported by the called endpoint.

 

 

Azure Function is just one of the services you can use with sp_invoke_external_rest_endpoint. In fact, you can call any of the following Azure services:

 

Azure Service
Azure Functions Azure Apps Service
Azure App Service Environment Azure Static Web Apps
Azure Logic Apps Azure Container Instances
Azure Event Grid Azure Event Hubs
PowerApps / Dataverse Azure Cognitive Services
Power BI Microsoft Graph
Analysis Services IoT Central
API Management  

 

Aside from calling an Azure Function, as you can see, you really have a lot of options which will enable you to create more user-friendly and responsive solutions. Just a few ideas, for example:

  • integrate with Azure Event Hubs and Azure Event Grid is extremely easy now to push data out of Azure SQL to make it available to event-driven solutions.
  • integrate with Power BI so that you can execute a DAX query using the executeQueries REST endpoint and get the result right into Azure SQL DB
  • invoke any REST endpoint anywhere in the world, thanks to the integration with API Management
  • send a notification to a SignalR website right from Azure SQL DB thanks to already mentioned Azure Function integration
  • enrich your data using AI and ML models – for example to detect anomalies – via the integration with Azure Cognitive Services

To learn everything about sp_invoke_external_rest_endpoint, the newly added security permission needed to use it, the support for Managed Service Identities and much more, take a look at the official documentation: sp_invoke_external_rest_endpoint (Transact-SQL) (Preview).

To make it easy to start and use sp_invoke_external_rest_endpoint right away, you can also use this GitHub Repo full of samples: azure-sql-db-invoke-external-rest-endpoints.

Enjoy and let us know if you like this feature and how you are using it, using the comment section below to give us your feedback and to tell us how you’d like to see this feature evolving, in the future. If you have some specific request, make sure to add it to the Azure SQL and SQL Server feedback portal, so that other users can contribute and help us prioritize future development. Looking forward to reading your ideas!

 

Updated Nov 16, 2022
Version 1.0
  • Thanks a lot for the feedback Morten!

     

    I'd like to follow up with you on the scenarios you have, to better understand your request. Please send me an email damauri@microsoft.com.

     

    Thanks!

  • MortenLange's avatar
    MortenLange
    Copper Contributor

    Hi,

    I have tried the the new 'sp_invoke_external_rest_endpoint'.  

    First of all, its amazing finally to be able to invoke endpoints and it opens a wide range of exciting appliances within both analytics and application development.  Now there is one more reason for using Azure SQL DB. 

     

    A few questions/wishes though

     

    a) Throttling

    It would be super nice if you either rise the cap for maximum worker threads (to for example 25 %) or even better make it configurable (with a default of 10 %).
    I see some possible beneficial appliances where a Azure SQL database will be configured for the sole purpose of invoke API calls. In such scenarios the database has to be scaled up impropertionally much to support the necessary concurrency.

     

    b)  Payload Size

    For many analytic appliances a maximum payload of 100 MB is not sufficient. If you can rise the max payload to 2 GB - like the native NVARCHAR(MAX) limit in Azure SQL Database -  it would be beneficial also.

     

    c) Managed Instance Support

    Is there any plan to support Azure SQL Managed Instance also in the future?

     

    Best regards,

    Morten Lange