Created
June 1, 2024 03:54
-
-
Save frueda1/d792b3fa0a743bf5a12003aebf94994f to your computer and use it in GitHub Desktop.
Webhook HTTP Request
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
using Serilog; | |
var builder = WebApplication.CreateBuilder(args); | |
// Add services to the container. | |
Log.Logger = new LoggerConfiguration() | |
.MinimumLevel.Information() | |
.Enrich.FromLogContext() | |
.Enrich.WithProcessId() | |
.Enrich.WithProcessName() | |
.WriteTo.File("../Logs/logFile.txt", rollingInterval: RollingInterval.Day, | |
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {CorrelationId} {Level:u3} {Properties} {Username} {Message:lj}{Exception}{NewLine}") | |
.CreateLogger(); | |
builder.Services.AddControllers(); | |
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | |
builder.Services.AddEndpointsApiExplorer(); | |
builder.Services.AddSwaggerGen(); | |
var app = builder.Build(); | |
// Configure the HTTP request pipeline. | |
if (app.Environment.IsDevelopment()) | |
{ | |
app.UseSwagger(); | |
app.UseSwaggerUI(); | |
} | |
app.UseHttpsRedirection(); | |
app.UseAuthorization(); | |
app.MapControllers(); | |
app.Run(); |
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 WebHooks.Models | |
{ | |
public class Response | |
{ | |
public string Message { get; set; } | |
public int StatusCode { get; set; } | |
} | |
} |
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
using Microsoft.AspNetCore.Mvc; | |
using Serilog; | |
using WebHooks.Models; | |
namespace WebHooks.Controllers | |
{ | |
[ApiController] | |
public class WebhookController : ControllerBase | |
{ | |
[HttpPost] | |
[Route("event")] | |
public Task<IActionResult> WebhookSample(object action) | |
{ | |
Log.Information("WebHook event handler call item {0}", action.ToString()); | |
return Task.FromResult<IActionResult>(Ok(new Response | |
{ | |
Message = "Ok", | |
StatusCode = StatusCodes.Status200OK | |
})); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment