New procedures added and addition of return execution value -1 when Exceptions occurs
Now, every procedure will return a default exectution value of 0 when it run suscessfully, and -1 if any exception happens. In this way, we will be able to identify when it failed, instead of returning 0 always.
Three new procedures were added;
-
APICaller_POST_Encoded ( fix Issue #30 )
This new procedure is exclusive for Call API with enconded contentType (application/x-www-form-urlencoded). -
Added APICaller_POST_Extended
-
Added APICaller_POST_Encoded
These two extended procedures enable the ability to change the content-type, through the header parameter.
--Set Header
Declare @header nvarchar(max) =
'[ {
"Name": "Content-Type",
"Value" :"application/json; charset=utf-8"
},
{
"Name": "X-RapidAPI-Host",
"Value" :"restcountries-v1.p.rapidapi.com"
},{
"Name": "X-RapidAPI-Key",
"Value" :"c56b333d25mshdbfec15f02f096ep19fa94jsne5189032cf7d"
}]';
And more important return information related to HTTP Response like:
(Hope this would help in issue #27)
- ContentType
- Server
- StatusCode
- Status Description
- Response Headers
Example:
USE TEstDB
--Set Header
Declare @header nvarchar(max) =
'[{
"Name": "Content-Type",
"Value" :"application/json; charset=utf-8"
},
{
"Name": "X-RapidAPI-Host",
"Value" :"restcountries-v1.p.rapidapi.com"
},{
"Name": "X-RapidAPI-Key",
"Value" :"c56b333d25mshdbfec15f02f096ep19fa94jsne5189032cf7d"
}]';
--Set URL
Declare @wurl varchar(max) = 'https://restcountries-v1.p.rapidapi.com/all'
Declare @ts as table
(
Json_Result nvarchar(max),
ContentType varchar(100),
ServerName varchar(100),
Statuscode varchar(100),
Descripcion varchar(100),
Json_Headers nvarchar(max)
)
declare @i as int
insert into @ts
--Get Account Data
exec @i = [dbo].[APICaller_GET_Extended]
@wurl
,''
,@header
select * from @ts
SELECT *
FROM OPENJSON((select Json_Result from @ts))
WITH (
name nvarchar(max) '$."name"'
,alpha2Code nvarchar(max) '$."alpha2Code"'
,alpha3Code nvarchar(max) '$."alpha3Code"'
,callingCodes nvarchar(max) '$."callingCodes"' as JSON
,capital nvarchar(max) '$."capital"'
,region nvarchar(max) '$."region"'
,subregion nvarchar(max) '$."subregion"'
,timezones nvarchar(max) '$."timezones"' as JSON
,population nvarchar(max) '$."population"'
,"currencies" nvarchar(max) '$."currencies"' as JSON
,languages nvarchar(max) '$."languages"' as JSON
) a
SELECT *
FROM OPENJSON((select Json_Headers from @ts))
WITH (
Header nvarchar(max) '$."Name"'
,Value nvarchar(max) '$."Value"'
) a