Nuget Packages:
- NPGSql
Steps:
-
Create a WepAPI app -Enable cors and set Json Serializer as default in startup.cs
public void ConfigureServices(IServiceCollection services) { //Enable CORS services.AddCors(c => { c.AddPolicy("AllowOrigin", options => options.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); }); //JSON Serializer services.AddControllersWithViews().AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore) .AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()); services.AddControllers(); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { //Enable Cors app.UseCors(options => options.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
-
Add DB in PgAdmin and create sample table
-
Add connection string under appsettings
-
Add controller and model
Run APP.