Skip to content

Instantly share code, notes, and snippets.

@frueda1
Created June 1, 2024 03:54
Show Gist options
  • Save frueda1/d792b3fa0a743bf5a12003aebf94994f to your computer and use it in GitHub Desktop.
Save frueda1/d792b3fa0a743bf5a12003aebf94994f to your computer and use it in GitHub Desktop.
Webhook HTTP Request
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();
namespace WebHooks.Models
{
public class Response
{
public string Message { get; set; }
public int StatusCode { get; set; }
}
}
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