Posts

Showing posts from May, 2025

How Create API in python using flask library

 from flask import Flask, request, jsonify app = Flask(__name__) # In-memory database items = {} # Get all items @app.route('/items', methods=['GET']) def get_items():     return jsonify(list(items.values())), 200 # Get a single item by ID @app.route('/items/<int:item_id>', methods=['GET']) def get_item(item_id):     item = items.get(item_id)     if item:         return jsonify(item), 200     return jsonify({'error': 'Item not found'}), 404 # Create a new item @app.route('/items', methods=['POST']) def create_item():     data = request.json     item_id = len(items) + 1     items[item_id] = {'id': item_id, 'name': data.get('name'), 'description': data.get('description')}     return jsonify(items[item_id]), 201 # Update an existing item @app.route('/items/<int:item_id>', methods=['PUT']) def update_item(item_id):     if item_id not in items:       ...

How implement serilog in dot net core

  Serilog in .NET Core, here's a quick guide: Steps to Implement Serilog in .NET Core: Install Serilog NuGet Packages Run the following command in your project:        dotnet add package Serilog.AspNetCore        dotnet add package Serilog.Sinks.Console         dotnet add package Serilog.Sinks.File       2. Configure Serilog in Program.cs Add the following code to set up logging: using Serilog; var builder = WebApplication.CreateBuilder(args); // Configure Serilog Log.Logger = new LoggerConfiguration()     .WriteTo.Console()     .WriteTo.File("logs/log.txt", rollingInterval: RollingInterval.Day)     .CreateLogger(); builder.Host.UseSerilog(); var app = builder.Build(); app.Run();     3.  Use Logging in Your Application Inject ILogger<T> into your services or controllers: public class MyService {     private readonly ILogger<MyService...