Last active
March 15, 2021 05:23
-
-
Save justinyoo/2b0b286bbe3e727e17423047cd97f86e to your computer and use it in GitHub Desktop.
Open API Extension to Support Azure Functions v1
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
namespace MyV1LegacyFunctionApp | |
{ | |
public static class LoremIpsumHttpTrigger | |
{ | |
[FunctionName("LoremIpsumHttpTrigger")] | |
public static async Task<HttpResponseMessage> Run( | |
[HttpTrigger(AuthorizationLevel.Function, "GET", Route = "lorem/ipsum")] HttpRequestMessage req, | |
ILogger log) | |
{ | |
var content = new MyReturnObject(); | |
var result = req.CreateResponse(HttpStatusCode.OK, content); | |
return await Task.FromResult(result).ConfigureAwait(false); } | |
} | |
} |
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
namespace MyV1ProxyFunctionApp | |
{ | |
public static class LoremIpsumHttpTrigger | |
{ | |
[FunctionName("LoremIpsumHttpTrigger")] | |
public static async Task<IActionResult> Run( | |
[HttpTrigger(AuthorizationLevel.Function, "GET", Route = "lorem/ipsum")] HttpRequest req, | |
ILogger log) | |
{ | |
return await Task.FromResult(new OkResult()).ConfigureAwait(false); | |
} | |
} | |
} |
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
namespace MyV1ProxyFunctionApp | |
{ | |
public static class LoremIpsumHttpTrigger | |
{ | |
[OpenApiOperation(operationId: "getIpsum", tags: new[] { "ipsum" }, Summary = "Gets Ipsum from Lorem", Description = "This gets Ipsum from Lorem.", Visibility = OpenApiVisibilityType.Important)] | |
[OpenApiParameter(name: "name", In = ParameterLocation.Query, Required = true, Type = typeof(string), Summary = "Lorem name", Description = "Lorem name", Visibility = OpenApiVisibilityType.Important)] | |
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(MyReturnObject), Summary = "The Ipsum response", Description = "This returns the Ipsum response")] | |
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.NotFound, Summary = "Name not found", Description = "Name parameter is not found")] | |
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.BadRequest, Summary = "Invalid Lorem", Description = "Lorem is not valid")] | |
[FunctionName("LoremIpsumHttpTrigger")] | |
public static async Task<IActionResult> Run( | |
[HttpTrigger(AuthorizationLevel.Function, "GET", Route = "lorem/ipsum")] HttpRequest req, | |
ILogger log) | |
{ | |
return await Task.FromResult(new OkResult()).ConfigureAwait(false); | |
} | |
} | |
} |
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
{ | |
"$schema": "http://json.schemastore.org/proxies", | |
"proxies": { | |
"LoremIpsumHttpTriggerProxy": { | |
"matchCondition": { | |
"route": "/api/lorem/ipsum", | |
"methods": [ | |
"GET" | |
] | |
}, | |
"backendUri": "https://mylegacyfunctionapp.azurewebsites.net/api/lorem/ipsum", | |
"requestOverrides": { | |
"backend.request.headers": "{request.headers}", | |
"backend.request.querystring": "{request.querystring}" | |
} | |
} | |
} | |
} |
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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<TargetFramework>netcoreapp3.1</TargetFramework> | |
<AzureFunctionsVersion>v3</AzureFunctionsVersion> | |
... | |
</PropertyGroup> | |
... | |
<ItemGroup> | |
... | |
<None Update="proxies.json"> | |
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | |
</None> | |
</ItemGroup> | |
... | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment