Make Axios send cookies in its requests automatically.
You can use the withCredentials
property.
axios.get(BASE_URL + '/todos', { withCredentials: true });
Also it is possible to force credentials to every Axios requests
axios.defaults.withCredentials = true
Or using credentials for some of the Axios requests as the following code
const instance = axios.create({
withCredentials: true,
baseURL: BASE_URL
})
instance.get('/todos')
Axios is a popular JavaScript library that simplifies HTTP requests, making it easy for beginners to interact with web services and APIs. With a simple and intuitive syntax, Axios provides a clean way to handle asynchronous tasks in web development. Whether fetching data or sending requests, Axios streamlines the process, enhancing the efficiency of frontend development.
Source app settings from key vault
Complete reference:
@Microsoft.KeyVault(SecretUri=https://myvault.vault.azure.net/secrets/mysecret/)
Alternatively:
@Microsoft.KeyVault(VaultName=myvault;SecretName=mysecret)
Source: Use Key Vault references - Azure App Service | Microsoft Learn
Variables declared with the const maintain constant values. const declarations share some similarities with let declarations.
Variables are containers for storing data in JavaScript. JavaScript variables can be declared in 4 ways:
var
: Declares a variable with function scope. It's less commonly used in modern JavaScript due to its potential for scope-related issues.
let
: Declares a variable with block scope, limiting it to the block or statement in which it's defined. It allows reassignment.
const
: Declares a constant variable with block scope. Once assigned, its value cannot be changed.
Choosing between them depends on your needs for variable scope and mutability. const
is preferred when you don't intend to change the variable's value, while let
is suitable for variables that need to be reassigned. var
is generally avoided in modern JavaScript due to its quirks related to scope.
We'll discuss the differences in Scope, Redeclaration, and Hoisting.
let is now preferred for variable declaration. It's no surprise as it comes as an improvement to var declarations. It also solves the problem with var that we just covered. Let's consider why this is so.
Before the advent of ES6, var declarations ruled. There are issues associated with variables declared with var, though. That is why new ways needed to declare variables to emerge.
The var
declares a variable with function scope.
JavaScript collections refer to data structures in the JavaScript programming language that are used to store and manipulate collections of values or objects. These collections provide various ways to organize and access data efficiently. There are several built-in collection types in JavaScript, and developers can also create custom collections as needed.
In JavaScript, collections like arrays, objects, sets, and maps are built-in language features. They are part of the core JavaScript language and do not require any external extensions or libraries to use. JavaScript provides these data structures as fundamental constructs for working with and organizing data within your programs.
JavaScript is a versatile and widely-used programming language, known for its ability to add interactivity and dynamic behavior to web pages. Key features include its simplicity, support for both front-end and back-end development, asynchronous capabilities, and a vast ecosystem of libraries and frameworks, making it essential for modern web development.
Arrays are ordered collections of values, and they are perhaps the most commonly used data structure in JavaScript. Elements in an array can be accessed by their index, and arrays can hold values of different data types.
let myArray = [1, 2, 3, 4, 5];
console.log(myArray[0]); // Accessing the first element
Objects in JavaScript are collections of key-value pairs. They are versatile and can be used to represent a wide range of data structures. Objects are often used for creating dictionaries, maps, and records.
let person = {
name: "Maria",
age: 28,
city: "New York"
};
console.log(person.name); // Accessing a property
Keys are always strings (or Symbols, introduced in ES6). When you use non-string values as keys in an object, JavaScript implicitly converts them to strings.
Objects are generally used for a simple dictionary-like structure with string keys.
This short Snipp shows you how to remove the last commit from the git repository.
1. Check the logs
First of all, check your local commit with messages before removing the last commit. Run the following command to check the logs in one line.
git log --oneline
2. Remove the last commit from the local branch
Now, Run the following command to remove the last commit and discard the changes from the local branch.
git reset --hard HEAD~1
Checkout the different ways to Undo commit before push in Git.
3. Update remote repository
At last, we will update the files and again need to push with force. It will delete the previous commit and keep a new one on the remote git repository.
git push origin <name_of_branch> -f
Now you can check the logs to verify the commit in the git repository.
The main workflow for a developer will follow these steps
This is an elementary guide to Git for beginners. Git is a version-control system for tracking changes in files associated with projects of different types. It is primarily used for source-code management in software development, but it can be used to keep track of changes in any set of files.
Without a version control system, you probably used to frequently save copies of your work-in-progress in zip files. But when you feel that your work is a mess and you need to get back to a previous version of some files, how to deal with mixed changes in files? It’s a real pain to do that. Git and other version control systems like SVN are a great solution.
In this example, you can see how you can manually manage a transaction around your database operations, providing more fine-grained control when needed. However, for most scenarios, the default behavior of wrapping SaveChanges
in a transaction is sufficient.
using (var dbContext = new YourDbContext())
{
using (var transaction = dbContext.Database.BeginTransaction())
{
try
{
// Perform your database operations here
dbContext.SaveChanges();
// If everything is successful, commit the transaction
transaction.Commit();
}
catch (Exception ex)
{
// Handle exceptions and optionally roll back the transaction
transaction.Rollback();
}
}
}
In this example, you can see how you can manually manage a transaction around your database operations, providing more fine-grained control when needed. However, for most scenarios, the default behavior of wrapping SaveChanges
in a transaction is sufficient.
Entity Framework Core (EF Core) does wrap the SaveChanges
method in a transaction by default. When you call SaveChanges
to persist changes to the database, EF Core ensures that all the changes are committed as a single transaction. This means that if any part of the operation fails (e.g., due to a validation error or a database constraint violation), none of the changes will be applied to the database.
Here's how it works:
SaveChanges
, EF Core starts a database transaction.This behavior ensures that your data remains in a consistent state, and either all changes are applied or none are. If you need more control over transactions, such as specifying isolation levels or manually managing transactions, EF Core provides options for doing so. You can use methods like BeginTransaction
, Commit
, and Rollback
on the DbContext's Database property to work with transactions explicitly.
EF Core Migrations is a feature that helps manage database schema changes. It allows developers to easily create, update, and rollback database migrations using a code-first approach, ensuring that your database schema stays in sync with your application models.