some changes
This commit is contained in:
50
forgetmenot-api/Bookmarks.cs
Normal file
50
forgetmenot-api/Bookmarks.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.WebJobs;
|
||||
using Microsoft.Azure.WebJobs.Extensions.Http;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
|
||||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace forgetmenot_api
|
||||
{
|
||||
public class Bookmarks
|
||||
{
|
||||
private readonly ILogger<Bookmarks> _logger;
|
||||
|
||||
public Bookmarks(ILogger<Bookmarks> log)
|
||||
{
|
||||
_logger = log;
|
||||
}
|
||||
|
||||
[FunctionName("bookmarks")]
|
||||
[OpenApiOperation(operationId: "Run", tags: new[] { "name" })]
|
||||
[OpenApiSecurity("function_key", SecuritySchemeType.ApiKey, Name = "code", In = OpenApiSecurityLocationType.Query)]
|
||||
[OpenApiParameter(name: "name", In = ParameterLocation.Query, Required = true, Type = typeof(string), Description = "The **Name** parameter")]
|
||||
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "text/plain", bodyType: typeof(string), Description = "The OK response")]
|
||||
public async Task<IActionResult> Run(
|
||||
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req)
|
||||
{
|
||||
_logger.LogInformation("C# HTTP trigger function processed a request.");
|
||||
_logger.LogInformation("Just log something");
|
||||
|
||||
string name = req.Query["name"];
|
||||
|
||||
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
|
||||
dynamic data = JsonConvert.DeserializeObject(requestBody);
|
||||
name = name ?? data?.name;
|
||||
|
||||
string responseMessage = string.IsNullOrEmpty(name)
|
||||
? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
|
||||
: $"Hello, {name}. This HTTP triggered function executed successfully.";
|
||||
|
||||
return new OkObjectResult(responseMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user