Posts

Showing posts from February, 2022

Understanding and Implementing Schemas in Python

Understanding and Implementing Schemas in Python Introduction In the world of programming, particularly in the context of data management and validation, schemas play a vital role. A schema is essentially a blueprint or a predefined structure that defines the expected format, data types, and constraints for a given data entity. In this blog, we will delve into the concept of schemas in Python, exploring what they are, why they are important, and how you can implement them in your projects. What is a Schema? A schema serves as a contract between different components of a system, ensuring that data is consistent, valid, and well-structured. It defines the rules for how data should be organized, what fields it should contain, and what types of values those fields can hold. In essence, a schema acts as a set of rules that data must adhere to in order to be considered valid. Why Are Schemas Important? Data Validation: Schemas provide a way to validate incoming data. When data is received o

How to fetch data using Axios Http Get Request in React Js?

Image
How to fetch data using  Axios - Http Get Request in React Js? In one of my previous post, I had explained all about Fetch() method to retrieve data from api server. In this post, I am going to demystify how to achieve same thing using axios. Axios has many advantages over fetch() method. 1) Axios has the ability to intercept HTTP request. 2) With axios.all() method, you can make simultaneous requests, simply send an array of request to this method, then use axios.spread() method to assign the properties of the response array to separate varialbes. 3) Axios automatically stringifies the data when sending requests, as in fetch() method, you would have to do it manually. 4) You can set response timeout. 5) Support backward compatibility, this is because it uses XMLhttprequest under the hood.  Fetch User Data Using Axios - Get Request Installation: npm install axios or yarn add axios Sample Code: A) index.js import   React   from   "react" ; import   ReactDOM   from   "rea

How to implement error boundaries in React Js

Error boundaries in React Js In this post, we will learn about "Error Boundaries in React Js". First of all, why we required Error Boundaries? This is the first question comes in my mind, as before React 16, we don't have any mechanism to catch error inside components and because of which whole app in broken state on next renders. No ways to handle these errors in React Components, nor it gives any methods to recover from them. React 16 introduces a new concept to handle such errors by using the error boundaries. So now, if any error found in a part of the UI, it does not break the whole application. According to official document of React Js, There are following few areas in application, where error boundaries are not suitable solution. a) Event handlers b) Asynchronous code (e.g., setTimeout) c) Server-side rendering d) Errors are thrown in the error boundary itself  For complex application which contains multiple components, we can declare multiple error boundaries to