-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* certified connector files created * api properties changes * invoke api changes * invoke api-generalised response changes * adding invoke api action to readme file --------- Co-authored-by: vetri-con861 <[email protected]> Co-authored-by: vetri-12980 <[email protected]>
- Loading branch information
1 parent
8b275ae
commit df78a27
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
public class Script : ScriptBase | ||
{ | ||
public override async Task<HttpResponseMessage> ExecuteAsync() | ||
{ | ||
return await this.HandleForwardOperation().ConfigureAwait(false); | ||
} | ||
private async Task<HttpResponseMessage> HandleForwardOperation() | ||
{ | ||
if(this.Context.OperationId == "InvokeAPI"){ | ||
return await this.HandleInvokeAPI().ConfigureAwait(false); | ||
} | ||
return null; | ||
} | ||
private async Task<HttpResponseMessage> HandleInvokeAPI() | ||
{ | ||
Uri uri = this.Context.Request.RequestUri; | ||
var query = HttpUtility.ParseQueryString(uri.Query); | ||
var apiMethod = HttpMethod.Get; | ||
switch (query["method"].ToString()) { | ||
case "GET": | ||
apiMethod = HttpMethod.Get; | ||
break; | ||
case "POST": | ||
apiMethod = HttpMethod.Post; | ||
break; | ||
case "PUT": | ||
apiMethod = HttpMethod.Put; | ||
break; | ||
} | ||
var updatedURL = Uri.UnescapeDataString(uri.ToString()); | ||
var apiUrl = updatedURL.Substring(0, updatedURL.IndexOf("?")); | ||
Context.Request.RequestUri = new System.Uri(string.Format(apiUrl)); | ||
Context.Request.Method = apiMethod; | ||
HttpResponseMessage response = await this.Context.SendAsync(this.Context.Request, this.CancellationToken).ConfigureAwait(continueOnCapturedContext: false); | ||
var responseString = await response.Content.ReadAsStringAsync().ConfigureAwait(continueOnCapturedContext: false); | ||
var responseJson = JObject.Parse(responseString); | ||
response.Content = CreateJsonContent(responseJson.ToString()); | ||
return response; | ||
} | ||
} |