Calling Http endpoints in T-SQL using CURL extension for ElasticSearch

This is another way to access the ElasticSearch integrated with T-SQL:
 
Sample code
===================================================
 
CREATE ASSEMBLY SqlClrCurl
FROM 'C:\GitHub\sql-server-samples\samples\features\sql-clr\Curl\bin\Release\SqlClrCurl.dll'
WITH PERMISSION_SET = EXTERNAL_ACCESS;
 
 
Once you import assembly, you can create a schema and functions that implement CURL functionalities in T-SQL
 
CREATE SCHEMA CURL;
GO
 
--Create the function/procedure
CREATE FUNCTION CURL.XGET (@H NVARCHAR(MAX), @url NVARCHAR(4000))
RETURNS NVARCHAR(MAX)
AS EXTERNAL NAME SqlClrCurl.Curl.Get;
GO
 
CREATE PROCEDURE CURL.XPOST (@H NVARCHAR(MAX), @d NVARCHAR(MAX), @url NVARCHAR(4000))
AS EXTERNAL NAME SqlClrCurl.Curl.Post;
 
 
 
T-SQL query Sample code
===================================================
 
select curl.xget(null, 'myElasticSearchURL')
 
 
T-SQL query Sample code for Requesting
===================================================
 
select curl.xget(null, 'myElasticSearchURL')
 
 
T-SQL query Sample code for Posting
===================================================
 
declare @hkey nvarchar(200) = N'aeg-sas-key: 9CwFFHbPIwTPVEdXS+W7eMnuPk1/+pouIlhzf5=';
 
declare @body nvarchar(4000) = N'[{"id":"1807","eventType":"recordInserted","subject":"myapp/vehicles/motorcycles","eventTime": "2017-08-10T21:03:07+00:00","data": {"make": "Ducati","model":"Monster"},"dataVersion":"1.0","metadataVersion":"1"}]';
 
declare @endpoint nvarchar(1000) = N'myElasticSearchURL';
 
exec curl.XPOST @H = @hkey, @d = @body, @url = @endpoint;This is another way to access the ElasticSearch integrated with T-SQL:
 
Sample code
===================================================
 
CREATE ASSEMBLY SqlClrCurl
FROM 'C:\GitHub\sql-server-samples\samples\features\sql-clr\Curl\bin\Release\SqlClrCurl.dll'
WITH PERMISSION_SET = EXTERNAL_ACCESS;
 
 
Once you import assembly, you can create a schema and functions that implement CURL functionalities in T-SQL
 
CREATE SCHEMA CURL;
GO
 
--Create the function/procedure
CREATE FUNCTION CURL.XGET (@H NVARCHAR(MAX), @url NVARCHAR(4000))
RETURNS NVARCHAR(MAX)
AS EXTERNAL NAME SqlClrCurl.Curl.Get;
GO
 
CREATE PROCEDURE CURL.XPOST (@H NVARCHAR(MAX), @d NVARCHAR(MAX), @url NVARCHAR(4000))
AS EXTERNAL NAME SqlClrCurl.Curl.Post;
 
 
 
T-SQL query Sample code
===================================================
 
select curl.xget(null, 'myElasticSearchURL')
 
 
T-SQL query Sample code for Requesting
===================================================
 
select curl.xget(null, 'myElasticSearchURL')
 
 
T-SQL query Sample code for Posting
===================================================
 
declare @hkey nvarchar(200) = N'aeg-sas-key: 9CwFFHbPIwTPVEdXS+W7eMnuPk1/+pouIlhzf5=';
 
declare @body nvarchar(4000) = N'[{"id":"1807","eventType":"recordInserted","subject":"myapp/vehicles/motorcycles","eventTime": "2017-08-10T21:03:07+00:00","data": {"make": "Ducati","model":"Monster"},"dataVersion":"1.0","metadataVersion":"1"}]';
 
declare @endpoint nvarchar(1000) = N'myElasticSearchURL';
 
exec curl.XPOST @H = @hkey, @d = @body, @url = @endpoint;