{"status":"ok","feed":{"url":"https://medium.com/feed/@mariya.aghafoor","title":"Stories by Mariya Abdul Ghafoor on Medium","link":"https://medium.com/@mariya.aghafoor?source=rss-c5df4976ed9f------2","author":"","description":"Stories by Mariya Abdul Ghafoor on Medium","image":"https://cdn-images-1.medium.com/fit/c/150/150/1*m4syTVY16bQo_KSDZMGO-A@2x.jpeg"},"items":[{"title":"I asked Reddit how to be the best dev","pubDate":"2024-07-25 12:40:00","link":"https://medium.com/@mariya.aghafoor/i-asked-reddit-how-to-be-the-best-dev-d497a741cef9?source=rss-c5df4976ed9f------2","guid":"https://medium.com/p/d497a741cef9","author":"Mariya Abdul Ghafoor","thumbnail":"","description":"\n<p>And got some great\u00a0advice.</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/0*XX5VmxIGli7aQ4tw\"><figcaption>Photo by <a href=\"https://unsplash.com/@brett_jordan?utm_source=medium&amp;utm_medium=referral\">Brett Jordan</a> on\u00a0<a href=\"https://unsplash.com/?utm_source=medium&amp;utm_medium=referral\">Unsplash</a></figcaption></figure><p>This is what I posted on\u00a0Reddit:</p>\n<h3><strong>I want to be the best\u00a0dev</strong></h3>\n<blockquote>So I am a boot camp graduate and have been working to gain confidence before I seriously apply for the dev roles. In short I want to be the best dev out there. My tech stack mainly includes JavaScript, Java, Spring boot and\u00a0React.</blockquote>\n<blockquote>\n<strong>Things I have\u00a0done</strong>:</blockquote>\n<blockquote>1. Make\u00a0projects</blockquote>\n<blockquote>2. Write blogs on the things I learn along the\u00a0way</blockquote>\n<blockquote>3. Build an online portfolio in\u00a0React</blockquote>\n<blockquote>4. Hosted a full stack app online ( React + Spring boot\u00a0API)</blockquote>\n<blockquote>5. Created a stackoverflow profile and answered a few questions</blockquote>\n<blockquote><strong>Things I am currently doing:</strong></blockquote>\n<blockquote>1. Leetcode</blockquote>\n<blockquote>2. Reading books on Java and Spring\u00a0boot</blockquote>\n<blockquote>3. Building more\u00a0projects</blockquote>\n<blockquote>What else do you suggest I do? Or is there anything I should do differently? Again I want to be the best in the game.\u00a0Thanks.</blockquote>\n<p>Many people were quick to point out that there are no best devs out there and the best I can be was a \u2018better\u2019 dev. Let me clarify something. I know perfection is not something that can be achieved but we can aim for it at least. So if you shoot for the moon and fail you will at least fall among the stars. That is my life\u2019s philosophy.</p>\n<p>Anyways back to the\u00a0advice\u2026</p>\n<p>Here I will reproduce some of the responses that I found\u00a0helpful</p>\n<h3><strong>1. Focus on Soft\u00a0Skills</strong></h3>\n<p><em>You seem to be on the right track, just keep in mind that the interviewer will also be looking for other soft skills such as collaborating with others on a large project, communication, handling conflicts/disagreements in the team etc. I\u2019ve seen many highly technically capable candidates faulter at this step in the hiring\u00a0process.</em></p>\n<h3><strong>2. Get a\u00a0Job</strong></h3>\n<p><em>You won\u2019t become the best, before getting a job and working on real-life projects. Nothing can truly prepare you for what it\u2019s like working with real people, and creating software for real\u00a0users.</em></p>\n<h3><strong>3. Reproduce parts of a framework</strong></h3>\n<p><em>Try a go at developing (parts of) the frameworks you use. That will give you a depth of understanding that a lot of bootcamp devs don\u2019t\u00a0have.</em></p>\n<h3><strong>4. Learn Github branching strategies</strong></h3>\n<p><em>It will be helpful if you understand the difference between the branching strategies as your future employer likely uses one. (Feature branching, release branching, git-flow, trunk based) as this will streamline how fast any code you write or change can be merged into a release. Consider it \u201cworking well with\u00a0others\u201d.</em></p>\n<h3>5. Build stuff that solve a\u00a0problem</h3>\n<p><em>A good way to know if worth pursuing a small side project is to say \u201cI made this because\u2026\u201d and it\u2019s in the \u201cbecause\u201d where the value is. You can code up anything but why did you do it and most importantly who is going to use\u00a0it.</em></p>\n<h3>6. Learn to break the\u00a0code</h3>\n<p><em>When working with code, ask yourself how you would break it, what inputs would break the flow, or cause security issues, or leak sensitive information.</em></p>\n<h3>7. Understand Design\u00a0Patterns</h3>\n<p><em>Learn about the various common development approaches like Domain Driven Design and the common patterns you will encounter and need to use to solve problems.</em></p>\n<h3>8. Other general\u00a0advice</h3>\n<ul>\n<li><em>The more languages you are competent at, the more tools you have available to you, it also provides you with different approaches to solving problems.</em></li>\n<li><em>Learn CICD\u00a0skills</em></li>\n<li><em>Learn about various testing systems, approaches, and methodologies.</em></li>\n<li><em>Learn defensive programming</em></li>\n<li><em>Practice your ability to document the code, projects, and how to write good VCS commit messages.</em></li>\n<li><em>Learn about containerizing your workloads, and how to make your code not run as root inside the container.</em></li>\n<li><em>Learn how to use and manage a database like Postgres and how to use\u00a0SQL.</em></li>\n<li><em>Contribute to open\u00a0source</em></li>\n<li><em>Animate meetups/workshop/conference</em></li>\n<li><em>Build a following</em></li>\n</ul>\n<p>In conclusion I would say that it is a pretty solid list and I would be focusing on it for the next few months until I become the best dev or die trying. Wish me\u00a0luck.</p>\n<img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=d497a741cef9\" width=\"1\" height=\"1\" alt=\"\">\n","content":"\n<p>And got some great\u00a0advice.</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/0*XX5VmxIGli7aQ4tw\"><figcaption>Photo by <a href=\"https://unsplash.com/@brett_jordan?utm_source=medium&amp;utm_medium=referral\">Brett Jordan</a> on\u00a0<a href=\"https://unsplash.com/?utm_source=medium&amp;utm_medium=referral\">Unsplash</a></figcaption></figure><p>This is what I posted on\u00a0Reddit:</p>\n<h3><strong>I want to be the best\u00a0dev</strong></h3>\n<blockquote>So I am a boot camp graduate and have been working to gain confidence before I seriously apply for the dev roles. In short I want to be the best dev out there. My tech stack mainly includes JavaScript, Java, Spring boot and\u00a0React.</blockquote>\n<blockquote>\n<strong>Things I have\u00a0done</strong>:</blockquote>\n<blockquote>1. Make\u00a0projects</blockquote>\n<blockquote>2. Write blogs on the things I learn along the\u00a0way</blockquote>\n<blockquote>3. Build an online portfolio in\u00a0React</blockquote>\n<blockquote>4. Hosted a full stack app online ( React + Spring boot\u00a0API)</blockquote>\n<blockquote>5. Created a stackoverflow profile and answered a few questions</blockquote>\n<blockquote><strong>Things I am currently doing:</strong></blockquote>\n<blockquote>1. Leetcode</blockquote>\n<blockquote>2. Reading books on Java and Spring\u00a0boot</blockquote>\n<blockquote>3. Building more\u00a0projects</blockquote>\n<blockquote>What else do you suggest I do? Or is there anything I should do differently? Again I want to be the best in the game.\u00a0Thanks.</blockquote>\n<p>Many people were quick to point out that there are no best devs out there and the best I can be was a \u2018better\u2019 dev. Let me clarify something. I know perfection is not something that can be achieved but we can aim for it at least. So if you shoot for the moon and fail you will at least fall among the stars. That is my life\u2019s philosophy.</p>\n<p>Anyways back to the\u00a0advice\u2026</p>\n<p>Here I will reproduce some of the responses that I found\u00a0helpful</p>\n<h3><strong>1. Focus on Soft\u00a0Skills</strong></h3>\n<p><em>You seem to be on the right track, just keep in mind that the interviewer will also be looking for other soft skills such as collaborating with others on a large project, communication, handling conflicts/disagreements in the team etc. I\u2019ve seen many highly technically capable candidates faulter at this step in the hiring\u00a0process.</em></p>\n<h3><strong>2. Get a\u00a0Job</strong></h3>\n<p><em>You won\u2019t become the best, before getting a job and working on real-life projects. Nothing can truly prepare you for what it\u2019s like working with real people, and creating software for real\u00a0users.</em></p>\n<h3><strong>3. Reproduce parts of a framework</strong></h3>\n<p><em>Try a go at developing (parts of) the frameworks you use. That will give you a depth of understanding that a lot of bootcamp devs don\u2019t\u00a0have.</em></p>\n<h3><strong>4. Learn Github branching strategies</strong></h3>\n<p><em>It will be helpful if you understand the difference between the branching strategies as your future employer likely uses one. (Feature branching, release branching, git-flow, trunk based) as this will streamline how fast any code you write or change can be merged into a release. Consider it \u201cworking well with\u00a0others\u201d.</em></p>\n<h3>5. Build stuff that solve a\u00a0problem</h3>\n<p><em>A good way to know if worth pursuing a small side project is to say \u201cI made this because\u2026\u201d and it\u2019s in the \u201cbecause\u201d where the value is. You can code up anything but why did you do it and most importantly who is going to use\u00a0it.</em></p>\n<h3>6. Learn to break the\u00a0code</h3>\n<p><em>When working with code, ask yourself how you would break it, what inputs would break the flow, or cause security issues, or leak sensitive information.</em></p>\n<h3>7. Understand Design\u00a0Patterns</h3>\n<p><em>Learn about the various common development approaches like Domain Driven Design and the common patterns you will encounter and need to use to solve problems.</em></p>\n<h3>8. Other general\u00a0advice</h3>\n<ul>\n<li><em>The more languages you are competent at, the more tools you have available to you, it also provides you with different approaches to solving problems.</em></li>\n<li><em>Learn CICD\u00a0skills</em></li>\n<li><em>Learn about various testing systems, approaches, and methodologies.</em></li>\n<li><em>Learn defensive programming</em></li>\n<li><em>Practice your ability to document the code, projects, and how to write good VCS commit messages.</em></li>\n<li><em>Learn about containerizing your workloads, and how to make your code not run as root inside the container.</em></li>\n<li><em>Learn how to use and manage a database like Postgres and how to use\u00a0SQL.</em></li>\n<li><em>Contribute to open\u00a0source</em></li>\n<li><em>Animate meetups/workshop/conference</em></li>\n<li><em>Build a following</em></li>\n</ul>\n<p>In conclusion I would say that it is a pretty solid list and I would be focusing on it for the next few months until I become the best dev or die trying. Wish me\u00a0luck.</p>\n<img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=d497a741cef9\" width=\"1\" height=\"1\" alt=\"\">\n","enclosure":{},"categories":["software-development","advice","best","programming","reddit"]},{"title":"How to enable CORS in Spring boot","pubDate":"2024-01-27 10:36:28","link":"https://towardsdev.com/how-to-enable-cors-in-spring-boot-ecaee4720d3c?source=rss-c5df4976ed9f------2","guid":"https://medium.com/p/ecaee4720d3c","author":"Mariya Abdul Ghafoor","thumbnail":"","description":"\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/0*l_fz6vV4272eai08\"><figcaption>Photo by <a href=\"https://unsplash.com/@marvelous?utm_source=medium&amp;utm_medium=referral\">Marvin Meyer</a> on\u00a0<a href=\"https://unsplash.com/?utm_source=medium&amp;utm_medium=referral\">Unsplash</a></figcaption></figure><p>Many people encounter a weird error when trying to access their Spring boot app from a web browser. I call it weird because the error does not appear while testing the app on Postman or through CURL. So what is going on and how to resolve\u00a0it?</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/864/1*neYYoKjdVk85pt333rHMNw.png\"><figcaption>CORS error in\u00a0Chrome</figcaption></figure><p>Before we look at the ways to tackle the error we first need to understand what exactly is\u00a0CORS.</p>\n<h3><strong>What is\u00a0CORS?</strong></h3>\n<blockquote>In simple words Cross-Origin Resource Sharing (<a href=\"https://developer.mozilla.org/en-US/docs/Glossary/CORS\">CORS</a>) is a mechanism through which browsers check whether an app\u2019s resources can be accessed from an origin that is different from where that app is\u00a0hosted.</blockquote>\n<p>This means that if your frontend is at <strong>localhost:5173</strong> while your Spring boot backend is running at <strong>localhost:3306</strong> you will be blocked from accessing your backend if you do not allow\u00a0CORS.</p>\n<p>That is why Postman steers clear of CORS error because it is strictly browser mechanism that happens on client\u2019s\u00a0side.</p>\n<h3><strong>How does CORS\u00a0work?</strong></h3>\n<p>When we make a fetch request from our frontend (browser) to our Spring boot backend, the browser first sends a \u201cpreflight\u201d request with headers that are the same as the actual request headers just to check if the server will allow the actual request or\u00a0not.</p>\n<p>If you go to Chrome dev tools and click on Network tab you can see all the requests that your browser has\u00a0made.</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*Y_xuwFwQTTKK_gp0I1D7sQ.png\"><figcaption>Browser sends a preflight request before the actual\u00a0request</figcaption></figure><h3><strong>How to enable CORS in\u00a0Spring?</strong></h3>\n<p>Spring provides different ways to configure CORS in your spring app. If you do not configure it then by default Cross origin requests will be\u00a0blocked.</p>\n<p><strong>Enable CORS\u00a0globally</strong></p>\n<p>This means allow all origins to access your Spring boot app. This could be dangerous as the purpose of CORS is to defend against malicious sites making request on your behalf. For example you could have your banking website open on one tab while another malicious website on another tab. That website can make requests to your bank on your behalf. Pretty\u00a0scary!</p>\n<p>Anyways if you are just testing and are not bothered about your app\u2019s security the easiest way to get past CORS error is to just enable it globally. Add the following file to your config\u00a0folder.</p>\n<pre>import org.springframework.context.annotation.Configuration;<br>import org.springframework.web.servlet.config.annotation.CorsRegistry;<br>import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;<br><br>@Configuration<br>public class WebConfig implements WebMvcConfigurer{<br>  public void addCorsMappings(CorsRegistry registry) {<br><br>    registry.addMapping(\"/**\")<br>        .allowedOrigins(\"*\") //allow all origins<br>        .allowedMethods(\"GET\", \"POST\", \"DELETE\", \"PATCH\")<br>        .allowedHeaders(\"*\");<br><br>  }<br>}</pre>\n<p>That is all you need to do. Even if you are using Spring security this is sufficient to enable CORS globally!</p>\n<p><strong>Enable CORS for specific paths using @CrossOrigin Annotation</strong></p>\n<p>You can use Spring\u2019s @CrossOrigin annotation to enable CORS in your Controller class. You can either use the annotation at class level or at method\u00a0level.</p>\n<p>To enable CORS for the whole controller class</p>\n<pre>@CrossOrigin(origins = \"http://domain2.com\", maxAge = 3600)<br>@RestController<br>@RequestMapping(\"/account\")<br>public class AccountController {<br><br> @GetMapping(\"/{id}\")<br> public Account retrieve(@PathVariable Long id) {<br>  // ...<br> }<br><br> @DeleteMapping(\"/{id}\")<br> public void remove(@PathVariable Long id) {<br>  // ...<br> }<br>}</pre>\n<p>To enable CORS for specific methods in controller:</p>\n<pre>@RestController<br>@RequestMapping(\"/account\")<br>public class AccountController {<br><br> @CrossOrigin<br> @GetMapping(\"/{id}\")<br> public Account retrieve(@PathVariable Long id) {<br>  // ...<br> }<br><br> @DeleteMapping(\"/{id}\")<br> public void remove(@PathVariable Long id) {<br>  // ...<br> }<br>}</pre>\n<p>That is all you need to do to tackle the dreaded CORS error in your web\u00a0browser.</p>\n<p>If you liked this write-up please give a clap and follow for\u00a0more.</p>\n<p>I aim to write about complex programming concepts with intimidating jargon in plain understandable language.</p>\n<p>Further reading: <a href=\"https://spring.io/blog/2015/06/08/cors-support-in-spring-framework\">CORS support in Spring Framework</a></p>\n<img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=ecaee4720d3c\" width=\"1\" height=\"1\" alt=\"\"><hr>\n<p><a href=\"https://towardsdev.com/how-to-enable-cors-in-spring-boot-ecaee4720d3c\">How to enable CORS in Spring boot</a> was originally published in <a href=\"https://towardsdev.com/\">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>\n","content":"\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/0*l_fz6vV4272eai08\"><figcaption>Photo by <a href=\"https://unsplash.com/@marvelous?utm_source=medium&amp;utm_medium=referral\">Marvin Meyer</a> on\u00a0<a href=\"https://unsplash.com/?utm_source=medium&amp;utm_medium=referral\">Unsplash</a></figcaption></figure><p>Many people encounter a weird error when trying to access their Spring boot app from a web browser. I call it weird because the error does not appear while testing the app on Postman or through CURL. So what is going on and how to resolve\u00a0it?</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/864/1*neYYoKjdVk85pt333rHMNw.png\"><figcaption>CORS error in\u00a0Chrome</figcaption></figure><p>Before we look at the ways to tackle the error we first need to understand what exactly is\u00a0CORS.</p>\n<h3><strong>What is\u00a0CORS?</strong></h3>\n<blockquote>In simple words Cross-Origin Resource Sharing (<a href=\"https://developer.mozilla.org/en-US/docs/Glossary/CORS\">CORS</a>) is a mechanism through which browsers check whether an app\u2019s resources can be accessed from an origin that is different from where that app is\u00a0hosted.</blockquote>\n<p>This means that if your frontend is at <strong>localhost:5173</strong> while your Spring boot backend is running at <strong>localhost:3306</strong> you will be blocked from accessing your backend if you do not allow\u00a0CORS.</p>\n<p>That is why Postman steers clear of CORS error because it is strictly browser mechanism that happens on client\u2019s\u00a0side.</p>\n<h3><strong>How does CORS\u00a0work?</strong></h3>\n<p>When we make a fetch request from our frontend (browser) to our Spring boot backend, the browser first sends a \u201cpreflight\u201d request with headers that are the same as the actual request headers just to check if the server will allow the actual request or\u00a0not.</p>\n<p>If you go to Chrome dev tools and click on Network tab you can see all the requests that your browser has\u00a0made.</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*Y_xuwFwQTTKK_gp0I1D7sQ.png\"><figcaption>Browser sends a preflight request before the actual\u00a0request</figcaption></figure><h3><strong>How to enable CORS in\u00a0Spring?</strong></h3>\n<p>Spring provides different ways to configure CORS in your spring app. If you do not configure it then by default Cross origin requests will be\u00a0blocked.</p>\n<p><strong>Enable CORS\u00a0globally</strong></p>\n<p>This means allow all origins to access your Spring boot app. This could be dangerous as the purpose of CORS is to defend against malicious sites making request on your behalf. For example you could have your banking website open on one tab while another malicious website on another tab. That website can make requests to your bank on your behalf. Pretty\u00a0scary!</p>\n<p>Anyways if you are just testing and are not bothered about your app\u2019s security the easiest way to get past CORS error is to just enable it globally. Add the following file to your config\u00a0folder.</p>\n<pre>import org.springframework.context.annotation.Configuration;<br>import org.springframework.web.servlet.config.annotation.CorsRegistry;<br>import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;<br><br>@Configuration<br>public class WebConfig implements WebMvcConfigurer{<br>  public void addCorsMappings(CorsRegistry registry) {<br><br>    registry.addMapping(\"/**\")<br>        .allowedOrigins(\"*\") //allow all origins<br>        .allowedMethods(\"GET\", \"POST\", \"DELETE\", \"PATCH\")<br>        .allowedHeaders(\"*\");<br><br>  }<br>}</pre>\n<p>That is all you need to do. Even if you are using Spring security this is sufficient to enable CORS globally!</p>\n<p><strong>Enable CORS for specific paths using @CrossOrigin Annotation</strong></p>\n<p>You can use Spring\u2019s @CrossOrigin annotation to enable CORS in your Controller class. You can either use the annotation at class level or at method\u00a0level.</p>\n<p>To enable CORS for the whole controller class</p>\n<pre>@CrossOrigin(origins = \"http://domain2.com\", maxAge = 3600)<br>@RestController<br>@RequestMapping(\"/account\")<br>public class AccountController {<br><br> @GetMapping(\"/{id}\")<br> public Account retrieve(@PathVariable Long id) {<br>  // ...<br> }<br><br> @DeleteMapping(\"/{id}\")<br> public void remove(@PathVariable Long id) {<br>  // ...<br> }<br>}</pre>\n<p>To enable CORS for specific methods in controller:</p>\n<pre>@RestController<br>@RequestMapping(\"/account\")<br>public class AccountController {<br><br> @CrossOrigin<br> @GetMapping(\"/{id}\")<br> public Account retrieve(@PathVariable Long id) {<br>  // ...<br> }<br><br> @DeleteMapping(\"/{id}\")<br> public void remove(@PathVariable Long id) {<br>  // ...<br> }<br>}</pre>\n<p>That is all you need to do to tackle the dreaded CORS error in your web\u00a0browser.</p>\n<p>If you liked this write-up please give a clap and follow for\u00a0more.</p>\n<p>I aim to write about complex programming concepts with intimidating jargon in plain understandable language.</p>\n<p>Further reading: <a href=\"https://spring.io/blog/2015/06/08/cors-support-in-spring-framework\">CORS support in Spring Framework</a></p>\n<img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=ecaee4720d3c\" width=\"1\" height=\"1\" alt=\"\"><hr>\n<p><a href=\"https://towardsdev.com/how-to-enable-cors-in-spring-boot-ecaee4720d3c\">How to enable CORS in Spring boot</a> was originally published in <a href=\"https://towardsdev.com/\">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>\n","enclosure":{},"categories":["error","spring","security","chrome","cors"]},{"title":"How to display latest Medium blogs on your website","pubDate":"2024-01-10 12:01:45","link":"https://towardsdev.com/how-to-use-mediums-api-to-display-live-blogs-on-your-website-0fb2e2535cab?source=rss-c5df4976ed9f------2","guid":"https://medium.com/p/0fb2e2535cab","author":"Mariya Abdul Ghafoor","thumbnail":"","description":"\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*RB1rxSK_TBmcC5D2PN30JA.png\"></figure><p>Medium has an <a href=\"https://github.com/Medium/medium-api-docs?tab=readme-ov-file#3-resources\">API</a> that allows users to post content directly through their apps. But if you want to retrieve content to display on your website the API is kinda\u00a0useless\u2026</p>\n<h3><strong>Generating API End Point to Retrieve Blog\u00a0Posts</strong></h3>\n<p>Fear not as there is another very easy way through which we can retrieve a particular user\u2019s posts. We can use RSS\u00a0feed.</p>\n<blockquote>An RSS (Really Simple Syndication) feed is an online file that contains details about every piece of content a site has published.</blockquote>\n<p>We can access Medium\u2019s RSS feed through this url: <a href=\"https://medium.com/feed/@%3Cuser%3E\">https://medium.com/feed/@&lt;user&gt;</a></p>\n<p><em>[Replace &lt;user&gt; with the username of the person whose blogs you want to retrieve].</em></p>\n<p>The url returns XML formatted data like\u00a0this:</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*oaSi5IdWMPPI7N2sTtgR0A.png\"><figcaption>XML data received from RSS feed of my\u00a0blogs</figcaption></figure><p>Now we need to parse the data to JSON so we can use it in our React app. To do that we will use an online JSON parser <a href=\"https://rss2json.com/\">https://rss2json.com/</a>. We will provide our RSS feed link and it will generate a new link which we can then use directly in our app. For my blogs the following link would work: <a href=\"https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/@mariya.aghafoor\">https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/@mariya.aghafoor</a></p>\n<h3>Testing the API\u00a0Endpoint</h3>\n<p>To test whether the generated endpoint works head to <a href=\"https://www.postman.com/\">Postman</a> and make a GET\u00a0request.</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*oiWKnCRCX0JvXLUdSi1X3w.png\"><figcaption>Result to API\u00a0call</figcaption></figure><p>Now the field that we are interested in is \u2018<em>items</em>\u2019 which has all the information about the blog posts. Under items we will access keys of \u2018<em>title</em>\u2019 and \u2018<em>content</em>\u2019 which has the featured image as a value. For some reason the \u2018<em>thumbnail</em>\u2019 key was returning an empty string so I had to figure out a way to access featured image from \u2018<em>content</em>\u2019 key.</p>\n<h3>Creating a Service in\u00a0React</h3>\n<p>Now that we have a url to fetch from we will create a service called <em>getBlogs</em> under services folder in our React app. We are using fetch to get data from our\u00a0API.</p>\n<pre>export const getBlogs = async () =&gt; {<br>  const response = await fetch(<br>    \"https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/@mariya.aghafoor\"<br>  );<br>  const data = await response.json();<br>  console.log(\"got data\");<br><br>  console.log(data);<br>  return data;<br>};</pre>\n<p>Now we need a component where we can call this service function. We will get the JSON formatted data from which we will access the \u2018<em>items</em>\u2019 key. We need to map the data and create Cards for each of the blog\u00a0post.</p>\n<pre>import { getBlogs } from \"../../services/getBlogs\";<br>import { useEffect, useState } from \"react\";<br>import BlogCard from \"../BlogCard/BlogCard\";<br><br>function Blogs() {<br>  const [blogs, setBlogs] = useState([]);<br>  useEffect(() =&gt; {<br>    getBlogs().then((data) =&gt; {<br>      setBlogs(data.items);<br>    });<br>  }, []);<br>  return (<br>    &lt;&gt;<br>      {blogs &amp;&amp; (<br>        &lt;div&gt;<br>          {blogs.map((item, index) =&gt; (<br>            &lt;BlogCard key={index} blog={item} /&gt;<br>          ))}<br>        &lt;/div&gt;<br>      )}<br>    &lt;/&gt;<br>  );<br>}<br><br>export default Blogs;</pre>\n<p>Now we will create a BlogCard component which will be rendered for each blog\u00a0post.</p>\n<pre>function BlogCard({ blog }) {  <br>  let imageTagStr = blog.description.match(/&lt;img\\s+[^&gt;]*src=\"([^\"]*)\"[^&gt;]*&gt;/i);<br>  let imageUrl = imageTagStr[1];<br>  return (<br>    &lt;&gt;<br>      &lt;div&gt;<br>        &lt;a href={blog.guid} target=\"_blank\" rel=\"noreferrer\"&gt;<br>          &lt;img src={imageUrl} alt={blog.title} /&gt;<br>        &lt;/a&gt;<br><br>        &lt;h3&gt;{blog.title}&lt;/h3&gt;<br>      &lt;/div&gt;<br><br>    &lt;/&gt;<br>  );<br>}<br><br>export default BlogCard;</pre>\n<p>As you can see from above that to get featured image I had to parse the data in the \u2018<em>content\u2019</em> field. First I use a Regex to get all the images\u2019 urls then I save the first image url to a imageUrl variable which is later used as a source for our\u00a0image.</p>\n<p>This is how the result looks like after some\u00a0styling:</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*0ylzWV9rEauJaxKxfW4Kfw.png\"><figcaption>Medium blogs feed on my portfolio website</figcaption></figure><p>That\u2019s it! Now we have live feed of our favourite user\u2019s Medium blogs on our\u00a0website.</p>\n<p>If you want to have a look at the full code here is a <a href=\"https://github.com/Mariya-ghafoor/personal-portfolio-react?tab=readme-ov-file\">link</a> to my portfolio\u2019s repo on\u00a0GitHub.</p>\n<p>If you liked this write-up please clap for it and follow me and be\u00a0cool.</p>\n<a href=\"https://medium.com/media/5829cfecc39f4478b22ca05fae3fe5d0/href\">https://medium.com/media/5829cfecc39f4478b22ca05fae3fe5d0/href</a><img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=0fb2e2535cab\" width=\"1\" height=\"1\" alt=\"\"><hr>\n<p><a href=\"https://towardsdev.com/how-to-use-mediums-api-to-display-live-blogs-on-your-website-0fb2e2535cab\">How to display latest Medium blogs on your website</a> was originally published in <a href=\"https://towardsdev.com/\">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>\n","content":"\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*RB1rxSK_TBmcC5D2PN30JA.png\"></figure><p>Medium has an <a href=\"https://github.com/Medium/medium-api-docs?tab=readme-ov-file#3-resources\">API</a> that allows users to post content directly through their apps. But if you want to retrieve content to display on your website the API is kinda\u00a0useless\u2026</p>\n<h3><strong>Generating API End Point to Retrieve Blog\u00a0Posts</strong></h3>\n<p>Fear not as there is another very easy way through which we can retrieve a particular user\u2019s posts. We can use RSS\u00a0feed.</p>\n<blockquote>An RSS (Really Simple Syndication) feed is an online file that contains details about every piece of content a site has published.</blockquote>\n<p>We can access Medium\u2019s RSS feed through this url: <a href=\"https://medium.com/feed/@%3Cuser%3E\">https://medium.com/feed/@&lt;user&gt;</a></p>\n<p><em>[Replace &lt;user&gt; with the username of the person whose blogs you want to retrieve].</em></p>\n<p>The url returns XML formatted data like\u00a0this:</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*oaSi5IdWMPPI7N2sTtgR0A.png\"><figcaption>XML data received from RSS feed of my\u00a0blogs</figcaption></figure><p>Now we need to parse the data to JSON so we can use it in our React app. To do that we will use an online JSON parser <a href=\"https://rss2json.com/\">https://rss2json.com/</a>. We will provide our RSS feed link and it will generate a new link which we can then use directly in our app. For my blogs the following link would work: <a href=\"https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/@mariya.aghafoor\">https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/@mariya.aghafoor</a></p>\n<h3>Testing the API\u00a0Endpoint</h3>\n<p>To test whether the generated endpoint works head to <a href=\"https://www.postman.com/\">Postman</a> and make a GET\u00a0request.</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*oiWKnCRCX0JvXLUdSi1X3w.png\"><figcaption>Result to API\u00a0call</figcaption></figure><p>Now the field that we are interested in is \u2018<em>items</em>\u2019 which has all the information about the blog posts. Under items we will access keys of \u2018<em>title</em>\u2019 and \u2018<em>content</em>\u2019 which has the featured image as a value. For some reason the \u2018<em>thumbnail</em>\u2019 key was returning an empty string so I had to figure out a way to access featured image from \u2018<em>content</em>\u2019 key.</p>\n<h3>Creating a Service in\u00a0React</h3>\n<p>Now that we have a url to fetch from we will create a service called <em>getBlogs</em> under services folder in our React app. We are using fetch to get data from our\u00a0API.</p>\n<pre>export const getBlogs = async () =&gt; {<br>  const response = await fetch(<br>    \"https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/@mariya.aghafoor\"<br>  );<br>  const data = await response.json();<br>  console.log(\"got data\");<br><br>  console.log(data);<br>  return data;<br>};</pre>\n<p>Now we need a component where we can call this service function. We will get the JSON formatted data from which we will access the \u2018<em>items</em>\u2019 key. We need to map the data and create Cards for each of the blog\u00a0post.</p>\n<pre>import { getBlogs } from \"../../services/getBlogs\";<br>import { useEffect, useState } from \"react\";<br>import BlogCard from \"../BlogCard/BlogCard\";<br><br>function Blogs() {<br>  const [blogs, setBlogs] = useState([]);<br>  useEffect(() =&gt; {<br>    getBlogs().then((data) =&gt; {<br>      setBlogs(data.items);<br>    });<br>  }, []);<br>  return (<br>    &lt;&gt;<br>      {blogs &amp;&amp; (<br>        &lt;div&gt;<br>          {blogs.map((item, index) =&gt; (<br>            &lt;BlogCard key={index} blog={item} /&gt;<br>          ))}<br>        &lt;/div&gt;<br>      )}<br>    &lt;/&gt;<br>  );<br>}<br><br>export default Blogs;</pre>\n<p>Now we will create a BlogCard component which will be rendered for each blog\u00a0post.</p>\n<pre>function BlogCard({ blog }) {  <br>  let imageTagStr = blog.description.match(/&lt;img\\s+[^&gt;]*src=\"([^\"]*)\"[^&gt;]*&gt;/i);<br>  let imageUrl = imageTagStr[1];<br>  return (<br>    &lt;&gt;<br>      &lt;div&gt;<br>        &lt;a href={blog.guid} target=\"_blank\" rel=\"noreferrer\"&gt;<br>          &lt;img src={imageUrl} alt={blog.title} /&gt;<br>        &lt;/a&gt;<br><br>        &lt;h3&gt;{blog.title}&lt;/h3&gt;<br>      &lt;/div&gt;<br><br>    &lt;/&gt;<br>  );<br>}<br><br>export default BlogCard;</pre>\n<p>As you can see from above that to get featured image I had to parse the data in the \u2018<em>content\u2019</em> field. First I use a Regex to get all the images\u2019 urls then I save the first image url to a imageUrl variable which is later used as a source for our\u00a0image.</p>\n<p>This is how the result looks like after some\u00a0styling:</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*0ylzWV9rEauJaxKxfW4Kfw.png\"><figcaption>Medium blogs feed on my portfolio website</figcaption></figure><p>That\u2019s it! Now we have live feed of our favourite user\u2019s Medium blogs on our\u00a0website.</p>\n<p>If you want to have a look at the full code here is a <a href=\"https://github.com/Mariya-ghafoor/personal-portfolio-react?tab=readme-ov-file\">link</a> to my portfolio\u2019s repo on\u00a0GitHub.</p>\n<p>If you liked this write-up please clap for it and follow me and be\u00a0cool.</p>\n<a href=\"https://medium.com/media/5829cfecc39f4478b22ca05fae3fe5d0/href\">https://medium.com/media/5829cfecc39f4478b22ca05fae3fe5d0/href</a><img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=0fb2e2535cab\" width=\"1\" height=\"1\" alt=\"\"><hr>\n<p><a href=\"https://towardsdev.com/how-to-use-mediums-api-to-display-live-blogs-on-your-website-0fb2e2535cab\">How to display latest Medium blogs on your website</a> was originally published in <a href=\"https://towardsdev.com/\">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>\n","enclosure":{},"categories":["api","blog","website","medium","live"]},{"title":"Deploy React+Spring Boot+MySql App for Free! Step-by-Step Guide","pubDate":"2024-01-02 11:12:48","link":"https://towardsdev.com/deploy-react-spring-boot-mysql-app-for-free-step-by-step-guide-e2e73a1f3d92?source=rss-c5df4976ed9f------2","guid":"https://medium.com/p/e2e73a1f3d92","author":"Mariya Abdul Ghafoor","thumbnail":"","description":"\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/0*Gskj2nXLT6oJFWbI\"><figcaption>Photo by <a href=\"https://unsplash.com/@tvick?utm_source=medium&amp;utm_medium=referral\">Taylor Vick</a> on\u00a0<a href=\"https://unsplash.com/?utm_source=medium&amp;utm_medium=referral\">Unsplash</a></figcaption></figure><p>After I built my first full stack app I wanted to immediately deploy it. I soon found out that it was not as simple as deploying a static React website. In this tutorial I will share with you the way through which you can deploy your full stack app absolutely free!</p>\n<p>There are of course limitations to free services but if you have a personal project that you would like to show off to the world this is the right starting\u00a0point.</p>\n<p>Now I am assuming that you already have a React frontend app and a Spring boot backend that is performing CRUD operations on a MySql database on your computer.</p>\n<p><strong>Step 1: Create a database on the\u00a0cloud</strong></p>\n<p>Head to <a href=\"https://console.clever-cloud.com/\">https://clever-cloud.com/</a>, sign up and open their <a href=\"https://console.clever-cloud.com/\">console</a>. Click on Personal space on the left panel. Then Create an add-on and choose MySql from the list. Choose \u2018dev\u2019 (free version), provide a name and voila you now have a database ready to go. Now click on Export Environment Variables and copy the\u00a0values.</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/750/1*M7qM7N77QgSTUF-Hcm_VrA.png\"><figcaption>clever-cloud.com</figcaption></figure><p><strong>Step 2: Provide your database address to your Spring boot\u00a0app</strong></p>\n<p>Till now you must be running Spring boot locally with MySql database in your computer. Now we have a database set up on cloud so we need to tell our Spring boot app to access that database and create tables there. To do that we need to provide the above Environment variable values in our application.properties.</p>\n<pre>spring.datasource.url=jdbc:MYSQL_ADDON_URI<br>spring.datasource.username=MYSQL_ADDON_USER<br>spring.datasource.password=MYSQL_ADDON_PASSWORD</pre>\n<p>Before we move on to the next step make sure that you have your CORS configuration set to allow all connections else your browser will block your frontend from accessing backend. Create a file WebConfig.java and paste the following in\u00a0it:</p>\n<pre>import org.springframework.context.annotation.Configuration;<br>import org.springframework.web.servlet.config.annotation.CorsRegistry;<br>import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;<br><br>@Configuration<br>public class WebConfig implements WebMvcConfigurer {<br><br>  public void addCorsMappings(CorsRegistry registry) {<br><br>    registry.addMapping(\"/**\")<br>        .allowedOrigins(\"*\") //allow all origins<br>        .allowedMethods(\"GET\", \"POST\", \"DELETE\", \"PATCH\")<br>        .allowedHeaders(\"*\");<br>  }<br>}</pre>\n<p><strong>Step 3: Deploy your Spring boot\u00a0app</strong></p>\n<p>This is the most tricky step. I followed <a href=\"https://hostingtutorials.dev/blog/free-spring-boot-host-with-render\">this</a> tutorial to deploy my Spring boot app on Render. In short Render does not provide native support to Java so we need to create a Docker image\u00a0first.</p>\n<p>Follow the tutorial above to create a JAR file. Then create a Docker file in your project. Then create an account on Docker Hub and upload your image there. Go to Render and create a web service. Deploy the image from Docker hub and we are good to\u00a0go.</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*-Un--R6japR04uCe0GU6nw.png\"></figure><p><strong>Step 4: Deploy your React\u00a0app</strong></p>\n<p>If you have come this far then congratulations you are one step away from greatness.</p>\n<blockquote>Before you deploy your React app make sure you change the url to fetch the data to the one provided by Render. It would look something like <em>https://***.onrender.com/YOUR_TABLE_NAME.</em>\n</blockquote>\n<p>Deploying React app on <a href=\"https://www.netlify.com/\">Netlify</a> is as easy as a breeze. Before you do that just make sure to run this\u00a0locally:</p>\n<pre>npm run build</pre>\n<p>If your project has built successfully then head to Netlify. Click on Add new site \u2192 Import an Existing Project \u2192 Deploy with Github \u2192 Choose a repository and deploy. No need to change the configuration settings.</p>\n<p>Congratulations you have deployed your first full stack app on cloud and that too absolutely free!!!</p>\n<p><strong>Troubleshooting</strong></p>\n<p>On your way to greatness you will for sure stumble upon errors and failures. Do not be disheartened and follow the following tips:</p>\n<p><strong>Errors Deploying Spring boot\u00a0app</strong></p>\n<p>First and foremost turn on debug mode in spring boot. Add this property to your application.properties:</p>\n<pre>debug: true</pre>\n<p>It is very important to read the logs every time something fails.</p>\n<p>If you fail to create a JAR file look at the logs in the folder called \u2018sure-fire reports\u2019 under \u2018<strong>target</strong>\u2019\u00a0folder.</p>\n<p>If you fail to start your app locally then read the logs in the terminal.</p>\n<p>If the deployment fails on Render check the logs and see what is the road-block. In my case it many a times failed to connect to the database as the number of connections exceeded the free-tier limit which is 5. One way to solve this is to go to your database and kill all connections, then try\u00a0again.</p>\n<p>If that still does not work then you can try <a href=\"https://filess.io/\">https://filess.io/</a> which is another free database\u00a0service.</p>\n<p><strong>Errors deploying React\u00a0app</strong></p>\n<p>Usually the React apps deploy fast on Netlify which has a good native support for\u00a0React.</p>\n<p>If you have trouble viewing your images please make sure they are in the public\u00a0folder.</p>\n<p>That is all I learned on my journey to deploying a full stack app. If you have any questions you can comment below or email me at mariya.aghafoor@gmail.com.</p>\n<p>Happy deploying!</p>\n<img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=e2e73a1f3d92\" width=\"1\" height=\"1\" alt=\"\"><hr>\n<p><a href=\"https://towardsdev.com/deploy-react-spring-boot-mysql-app-for-free-step-by-step-guide-e2e73a1f3d92\">Deploy React+Spring Boot+MySql App for Free! Step-by-Step Guide</a> was originally published in <a href=\"https://towardsdev.com/\">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>\n","content":"\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/0*Gskj2nXLT6oJFWbI\"><figcaption>Photo by <a href=\"https://unsplash.com/@tvick?utm_source=medium&amp;utm_medium=referral\">Taylor Vick</a> on\u00a0<a href=\"https://unsplash.com/?utm_source=medium&amp;utm_medium=referral\">Unsplash</a></figcaption></figure><p>After I built my first full stack app I wanted to immediately deploy it. I soon found out that it was not as simple as deploying a static React website. In this tutorial I will share with you the way through which you can deploy your full stack app absolutely free!</p>\n<p>There are of course limitations to free services but if you have a personal project that you would like to show off to the world this is the right starting\u00a0point.</p>\n<p>Now I am assuming that you already have a React frontend app and a Spring boot backend that is performing CRUD operations on a MySql database on your computer.</p>\n<p><strong>Step 1: Create a database on the\u00a0cloud</strong></p>\n<p>Head to <a href=\"https://console.clever-cloud.com/\">https://clever-cloud.com/</a>, sign up and open their <a href=\"https://console.clever-cloud.com/\">console</a>. Click on Personal space on the left panel. Then Create an add-on and choose MySql from the list. Choose \u2018dev\u2019 (free version), provide a name and voila you now have a database ready to go. Now click on Export Environment Variables and copy the\u00a0values.</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/750/1*M7qM7N77QgSTUF-Hcm_VrA.png\"><figcaption>clever-cloud.com</figcaption></figure><p><strong>Step 2: Provide your database address to your Spring boot\u00a0app</strong></p>\n<p>Till now you must be running Spring boot locally with MySql database in your computer. Now we have a database set up on cloud so we need to tell our Spring boot app to access that database and create tables there. To do that we need to provide the above Environment variable values in our application.properties.</p>\n<pre>spring.datasource.url=jdbc:MYSQL_ADDON_URI<br>spring.datasource.username=MYSQL_ADDON_USER<br>spring.datasource.password=MYSQL_ADDON_PASSWORD</pre>\n<p>Before we move on to the next step make sure that you have your CORS configuration set to allow all connections else your browser will block your frontend from accessing backend. Create a file WebConfig.java and paste the following in\u00a0it:</p>\n<pre>import org.springframework.context.annotation.Configuration;<br>import org.springframework.web.servlet.config.annotation.CorsRegistry;<br>import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;<br><br>@Configuration<br>public class WebConfig implements WebMvcConfigurer {<br><br>  public void addCorsMappings(CorsRegistry registry) {<br><br>    registry.addMapping(\"/**\")<br>        .allowedOrigins(\"*\") //allow all origins<br>        .allowedMethods(\"GET\", \"POST\", \"DELETE\", \"PATCH\")<br>        .allowedHeaders(\"*\");<br>  }<br>}</pre>\n<p><strong>Step 3: Deploy your Spring boot\u00a0app</strong></p>\n<p>This is the most tricky step. I followed <a href=\"https://hostingtutorials.dev/blog/free-spring-boot-host-with-render\">this</a> tutorial to deploy my Spring boot app on Render. In short Render does not provide native support to Java so we need to create a Docker image\u00a0first.</p>\n<p>Follow the tutorial above to create a JAR file. Then create a Docker file in your project. Then create an account on Docker Hub and upload your image there. Go to Render and create a web service. Deploy the image from Docker hub and we are good to\u00a0go.</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*-Un--R6japR04uCe0GU6nw.png\"></figure><p><strong>Step 4: Deploy your React\u00a0app</strong></p>\n<p>If you have come this far then congratulations you are one step away from greatness.</p>\n<blockquote>Before you deploy your React app make sure you change the url to fetch the data to the one provided by Render. It would look something like <em>https://***.onrender.com/YOUR_TABLE_NAME.</em>\n</blockquote>\n<p>Deploying React app on <a href=\"https://www.netlify.com/\">Netlify</a> is as easy as a breeze. Before you do that just make sure to run this\u00a0locally:</p>\n<pre>npm run build</pre>\n<p>If your project has built successfully then head to Netlify. Click on Add new site \u2192 Import an Existing Project \u2192 Deploy with Github \u2192 Choose a repository and deploy. No need to change the configuration settings.</p>\n<p>Congratulations you have deployed your first full stack app on cloud and that too absolutely free!!!</p>\n<p><strong>Troubleshooting</strong></p>\n<p>On your way to greatness you will for sure stumble upon errors and failures. Do not be disheartened and follow the following tips:</p>\n<p><strong>Errors Deploying Spring boot\u00a0app</strong></p>\n<p>First and foremost turn on debug mode in spring boot. Add this property to your application.properties:</p>\n<pre>debug: true</pre>\n<p>It is very important to read the logs every time something fails.</p>\n<p>If you fail to create a JAR file look at the logs in the folder called \u2018sure-fire reports\u2019 under \u2018<strong>target</strong>\u2019\u00a0folder.</p>\n<p>If you fail to start your app locally then read the logs in the terminal.</p>\n<p>If the deployment fails on Render check the logs and see what is the road-block. In my case it many a times failed to connect to the database as the number of connections exceeded the free-tier limit which is 5. One way to solve this is to go to your database and kill all connections, then try\u00a0again.</p>\n<p>If that still does not work then you can try <a href=\"https://filess.io/\">https://filess.io/</a> which is another free database\u00a0service.</p>\n<p><strong>Errors deploying React\u00a0app</strong></p>\n<p>Usually the React apps deploy fast on Netlify which has a good native support for\u00a0React.</p>\n<p>If you have trouble viewing your images please make sure they are in the public\u00a0folder.</p>\n<p>That is all I learned on my journey to deploying a full stack app. If you have any questions you can comment below or email me at mariya.aghafoor@gmail.com.</p>\n<p>Happy deploying!</p>\n<img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=e2e73a1f3d92\" width=\"1\" height=\"1\" alt=\"\"><hr>\n<p><a href=\"https://towardsdev.com/deploy-react-spring-boot-mysql-app-for-free-step-by-step-guide-e2e73a1f3d92\">Deploy React+Spring Boot+MySql App for Free! Step-by-Step Guide</a> was originally published in <a href=\"https://towardsdev.com/\">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>\n","enclosure":{},"categories":["spring-boot","mysql","deploy","react","free"]},{"title":"Java recursion and variable passing: A step-by-step guide","pubDate":"2023-12-30 13:17:41","link":"https://towardsdev.com/how-recursive-methods-in-java-pass-variables-cb3c0cc63531?source=rss-c5df4976ed9f------2","guid":"https://medium.com/p/cb3c0cc63531","author":"Mariya Abdul Ghafoor","thumbnail":"","description":"\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/0*Fd83upwl9F8qQiNo\"><figcaption>Photo by <a href=\"https://unsplash.com/@fabioha?utm_source=medium&amp;utm_medium=referral\">fabio</a> on\u00a0<a href=\"https://unsplash.com/?utm_source=medium&amp;utm_medium=referral\">Unsplash</a></figcaption></figure><p>Recursion is a useful concept where a method calls itself until the base case is achieved. Base case is simply the condition where the method will terminate itself. Consider the following example:</p>\n<h3><strong>Java Recursion</strong></h3>\n<pre>public class MainClass {<br>2   public static void main(String[] args) {<br>3     <br>4     int count = 0;<br>5     testRecursion(count);<br>8     }<br>9   <br>10   public static void testRecursion(int count){<br>11     <br>12     System.out.println(\"Count = \"+count);<br>13     <br>14     if(count==3){<br>15       return;<br>16     }<br><br>19     count++;<br>20     testRecursion(count);<br>21     System.out.println(\"Count after recursion = \"+count);<br>22   }<br>23 }</pre>\n<p>In the above example the method testRecursion is calling itself. On each call the value of count increases by 1 (line 19). The method will keep calling until the base case is reached which is count = 3 (line\u00a014).</p>\n<p>If we do not have a base case then the method will go into an infinite loop until the program runs out of memory with a <em>StackOverflowError</em>.</p>\n<h3><strong>Recursion with Primitive data\u00a0type</strong></h3>\n<p>Now let\u2019s <a href=\"https://pythontutor.com/render.html#code=public%20class%20MainClass%20%7B%0A%20%20public%20static%20void%20main%28String%5B%5D%20args%29%20%7B%0A%20%20%20%20%0A%20%20%20%20int%20count%20%3D%200%3B%0A%20%20%20%20testRecursion%28count%29%3B%0A%20%20%20%20%0A%0A%20%20%7D%0A%20%20%0A%20%20public%20static%20void%20testRecursion%28int%20count%29%7B%0A%20%20%20%20%0A%20%20%20%20System.out.println%28%22Count%20%3D%20%22%2Bcount%29%3B%0A%20%20%20%20%0A%20%20%20%20if%28count%3D%3D3%29%7B%0A%20%20%20%20%20%20return%3B%0A%20%20%20%20%7D%0A%20%20%20%20%0A%20%20%20%20%0A%20%20%20%20count%2B%2B%3B%0A%20%20%20%20testRecursion%28count%29%3B%0A%20%20%20%20System.out.println%28%22Count%20after%20recursion%20%3D%20%22%2Bcount%29%3B%0A%7D%0A%7D&amp;cumulative=false&amp;curInstr=23&amp;heapPrimitives=nevernest&amp;mode=display&amp;origin=opt-frontend.js&amp;py=java&amp;rawInputLstJSON=%5B%5D&amp;textReferences=false\">visualise</a> the above\u00a0program:</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/882/1*gvHMh4bcny2z3Z5hZUrj6w.gif\"><figcaption>Recursion with primitive data type as a parameter</figcaption></figure><p>What is happening here? Why is count going back to its initial\u00a0value?</p>\n<p>This is because primitive variables passed by methods in Java are stored in stack\u00a0memory.</p>\n<blockquote>Stack memory is a type of memory in Java which is allocated when a method runs and is freed as soon as the method finishes.</blockquote>\n<p>This means that every time testRecursion method is called the value of count is stored in the stack. When the method finishes the stack is freed and hence the stored values are\u00a0lost.</p>\n<p>So what can we do if we want the program to retain the value of count? We use a non-primitive data type like an\u00a0array.</p>\n<h3><strong>Recursion with non-primitive data\u00a0type</strong></h3>\n<p>Consider the following example where count is replaced by an array called count with size\u00a01.</p>\n<pre>public class MainClass {<br>  public static void main(String[] args) {<br><br>    int[] count = new int[1];<br>    count[0] = 0;<br>    testRecursion(count);<br><br>  }<br><br>  public static void testRecursion(int[] count){<br><br>    System.out.println(\"Count = \"+count[0]);<br><br>    if(count[0]==3){<br>      return;<br>    }<br><br>    count[0]++;<br>    testRecursion(count);<br>    System.out.println(\"Count after recursion = \"+count[0]);<br>}<br>}</pre>\n<p>For non-primitive data types methods pass references and not actual values. This means that instead of the actual value of the object a reference to that object is stored in stack. When changes are made to the value of object the actual value is changed. That\u2019s why when the stack is freed the value of object is not lost as it is stored permanently in a different part of memory called\u00a0heap.</p>\n<blockquote>There is a technical point to note here: Java is always <strong>pass by value</strong> and never pass by reference. Even the non-primitive data types like arrays are passed as values but the difference is that the value contain reference to the object and not the actual value of the\u00a0object.</blockquote>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/890/1*b77p65hJXLEV5-cFUySU6A.gif\"><figcaption>Recursion with non-primitive data type as a parameter</figcaption></figure><p>As you can see from the above that the stack contains reference to the count array and whenever the value of count changes it is changed in the permanent part of the\u00a0memory.</p>\n<p>The last thing to note here is that while <strong><em>String</em></strong> is a non-primitive data type in Java it still behaves as a primitive data type when passed in a recursive method. This means that the String will lose its value as soon as the method finishes.</p>\n<p>That\u2019s all about Recursion and passing variables. If you liked this please consider following me. Also check out my other\u00a0blogs.</p>\n<img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=cb3c0cc63531\" width=\"1\" height=\"1\" alt=\"\"><hr>\n<p><a href=\"https://towardsdev.com/how-recursive-methods-in-java-pass-variables-cb3c0cc63531\">Java recursion and variable passing: A step-by-step guide</a> was originally published in <a href=\"https://towardsdev.com/\">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>\n","content":"\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/0*Fd83upwl9F8qQiNo\"><figcaption>Photo by <a href=\"https://unsplash.com/@fabioha?utm_source=medium&amp;utm_medium=referral\">fabio</a> on\u00a0<a href=\"https://unsplash.com/?utm_source=medium&amp;utm_medium=referral\">Unsplash</a></figcaption></figure><p>Recursion is a useful concept where a method calls itself until the base case is achieved. Base case is simply the condition where the method will terminate itself. Consider the following example:</p>\n<h3><strong>Java Recursion</strong></h3>\n<pre>public class MainClass {<br>2   public static void main(String[] args) {<br>3     <br>4     int count = 0;<br>5     testRecursion(count);<br>8     }<br>9   <br>10   public static void testRecursion(int count){<br>11     <br>12     System.out.println(\"Count = \"+count);<br>13     <br>14     if(count==3){<br>15       return;<br>16     }<br><br>19     count++;<br>20     testRecursion(count);<br>21     System.out.println(\"Count after recursion = \"+count);<br>22   }<br>23 }</pre>\n<p>In the above example the method testRecursion is calling itself. On each call the value of count increases by 1 (line 19). The method will keep calling until the base case is reached which is count = 3 (line\u00a014).</p>\n<p>If we do not have a base case then the method will go into an infinite loop until the program runs out of memory with a <em>StackOverflowError</em>.</p>\n<h3><strong>Recursion with Primitive data\u00a0type</strong></h3>\n<p>Now let\u2019s <a href=\"https://pythontutor.com/render.html#code=public%20class%20MainClass%20%7B%0A%20%20public%20static%20void%20main%28String%5B%5D%20args%29%20%7B%0A%20%20%20%20%0A%20%20%20%20int%20count%20%3D%200%3B%0A%20%20%20%20testRecursion%28count%29%3B%0A%20%20%20%20%0A%0A%20%20%7D%0A%20%20%0A%20%20public%20static%20void%20testRecursion%28int%20count%29%7B%0A%20%20%20%20%0A%20%20%20%20System.out.println%28%22Count%20%3D%20%22%2Bcount%29%3B%0A%20%20%20%20%0A%20%20%20%20if%28count%3D%3D3%29%7B%0A%20%20%20%20%20%20return%3B%0A%20%20%20%20%7D%0A%20%20%20%20%0A%20%20%20%20%0A%20%20%20%20count%2B%2B%3B%0A%20%20%20%20testRecursion%28count%29%3B%0A%20%20%20%20System.out.println%28%22Count%20after%20recursion%20%3D%20%22%2Bcount%29%3B%0A%7D%0A%7D&amp;cumulative=false&amp;curInstr=23&amp;heapPrimitives=nevernest&amp;mode=display&amp;origin=opt-frontend.js&amp;py=java&amp;rawInputLstJSON=%5B%5D&amp;textReferences=false\">visualise</a> the above\u00a0program:</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/882/1*gvHMh4bcny2z3Z5hZUrj6w.gif\"><figcaption>Recursion with primitive data type as a parameter</figcaption></figure><p>What is happening here? Why is count going back to its initial\u00a0value?</p>\n<p>This is because primitive variables passed by methods in Java are stored in stack\u00a0memory.</p>\n<blockquote>Stack memory is a type of memory in Java which is allocated when a method runs and is freed as soon as the method finishes.</blockquote>\n<p>This means that every time testRecursion method is called the value of count is stored in the stack. When the method finishes the stack is freed and hence the stored values are\u00a0lost.</p>\n<p>So what can we do if we want the program to retain the value of count? We use a non-primitive data type like an\u00a0array.</p>\n<h3><strong>Recursion with non-primitive data\u00a0type</strong></h3>\n<p>Consider the following example where count is replaced by an array called count with size\u00a01.</p>\n<pre>public class MainClass {<br>  public static void main(String[] args) {<br><br>    int[] count = new int[1];<br>    count[0] = 0;<br>    testRecursion(count);<br><br>  }<br><br>  public static void testRecursion(int[] count){<br><br>    System.out.println(\"Count = \"+count[0]);<br><br>    if(count[0]==3){<br>      return;<br>    }<br><br>    count[0]++;<br>    testRecursion(count);<br>    System.out.println(\"Count after recursion = \"+count[0]);<br>}<br>}</pre>\n<p>For non-primitive data types methods pass references and not actual values. This means that instead of the actual value of the object a reference to that object is stored in stack. When changes are made to the value of object the actual value is changed. That\u2019s why when the stack is freed the value of object is not lost as it is stored permanently in a different part of memory called\u00a0heap.</p>\n<blockquote>There is a technical point to note here: Java is always <strong>pass by value</strong> and never pass by reference. Even the non-primitive data types like arrays are passed as values but the difference is that the value contain reference to the object and not the actual value of the\u00a0object.</blockquote>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/890/1*b77p65hJXLEV5-cFUySU6A.gif\"><figcaption>Recursion with non-primitive data type as a parameter</figcaption></figure><p>As you can see from the above that the stack contains reference to the count array and whenever the value of count changes it is changed in the permanent part of the\u00a0memory.</p>\n<p>The last thing to note here is that while <strong><em>String</em></strong> is a non-primitive data type in Java it still behaves as a primitive data type when passed in a recursive method. This means that the String will lose its value as soon as the method finishes.</p>\n<p>That\u2019s all about Recursion and passing variables. If you liked this please consider following me. Also check out my other\u00a0blogs.</p>\n<img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=cb3c0cc63531\" width=\"1\" height=\"1\" alt=\"\"><hr>\n<p><a href=\"https://towardsdev.com/how-recursive-methods-in-java-pass-variables-cb3c0cc63531\">Java recursion and variable passing: A step-by-step guide</a> was originally published in <a href=\"https://towardsdev.com/\">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>\n","enclosure":{},"categories":["primitive-data-types","recursion","java","arrays","methods"]},{"title":"Create and initialize database automatically in Spring Boot","pubDate":"2023-12-21 13:59:02","link":"https://towardsdev.com/create-and-initialise-database-automatically-in-spring-boot-96d06fa99cc9?source=rss-c5df4976ed9f------2","guid":"https://medium.com/p/96d06fa99cc9","author":"Mariya Abdul Ghafoor","thumbnail":"","description":"\n<figure><img alt=\"Data is king\" src=\"https://cdn-images-1.medium.com/max/1024/1*GZQy1YhGdCMFLv5GoWQrRQ.png\"></figure><p>If you are working with a database in Spring boot the chances are you will need some initial data in the database for testing purpose. You may not want to manually create database and then send POST requests to enter values in your\u00a0tables.</p>\n<p>Spring boot makes it very easy to automate the whole process. From creating database, creating tables and filling them with initial data all could be done automatically when you start your spring boot\u00a0app.</p>\n<p>In this tutorial I will go through each step of database initialization.</p>\n<p><strong>Prerequisites</strong>: Basic knowledge of Spring boot with the ability to create a basic REST API. I will be working with a MySql database but you can use others. The process will remain the\u00a0same.</p>\n<h3><strong>Database Initialization in Spring\u00a0boot</strong></h3>\n<h3><strong>Step 1: Create\u00a0Database</strong></h3>\n<p>To tell Spring to create database as soon as your app runs add the following to your application.properties file:</p>\n<pre>spring.datasource.url=jdbc:mysql://localhost:3306/employees?createDatabaseIfNotExist=true<br>spring.datasource.username=root<br>spring.jpa.hibernate.ddl-auto=update</pre>\n<p>Replace \u2018<em>employees</em>\u2019 with the name of your database and \u20183306\u2019 with the port on which server is running. If you want you can specify the port by adding this property:</p>\n<pre>server.port=3306</pre>\n<h3><strong>Step 2: Create\u00a0Data.sql</strong></h3>\n<p>Now we need to create a file called Data.sql which will contain commands to fill our database. When the app runs Data.sql runs\u00a0first.</p>\n<blockquote>Remember! Always add Data.sql to your classpath which means it should be where your application.properties is i.e. in the <strong>resources</strong> folder.</blockquote>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/353/1*fxl1j7EKJOPTkB7Si3np1g.png\"><figcaption>data.sql should be in the resources folder</figcaption></figure><p>Now the question is how do we create data.sql? To create data.sql which will populate your database head to <a href=\"https://filldb.info/\">https://filldb.info/</a>\u00a0.</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*AROJvLd5Cdr84zuc6pM8Uw.png\"><figcaption>filldb.info</figcaption></figure><p>First we need to create a schema. Click <strong>Database Generator</strong>.</p>\n<p>Click New Table. Provide table name and fields. In my case table name was \u2018employees\u2019 and fields were \u2018firstName\u2019, \u2018lastName\u2019 and \u2018email\u2019. Then click \u2018Save table\u2019. Next click \u2018Generate Data\u2019 and choose your\u00a0table.</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*_4sy-Z3Tx5oSmyATwcM5jg.png\"></figure><p>Next click \u2018Generate data\u2019 and voila you have 100 rows of fake data that you can now export to your Spring boot\u00a0project.</p>\n<p>Click \u2018Export Employees\u2019 and rename the downloaded file as data.sql. Copy it to your resources folder.</p>\n<h3><strong>Step 3: Fill the\u00a0Database</strong></h3>\n<p>Now we need to add the following two properties to our application.properties:</p>\n<pre>spring.sql.init.mode=always<br>spring.jpa.defer-datasource-initialization=true</pre>\n<p>The first property will tell Spring to look for a sql file to initializa database.</p>\n<p>The second property will defer the loading of data.sql until Hibernate creates tables that are defined by our Entity component. We can also provide our own schema through schema.sql but we will not do that in this tutorial. Instead we will leave it to Hibernate to do that for\u00a0us.</p>\n<blockquote>In simple terms Hibernate is a tool to map Java objects to relational databases</blockquote>\n<p>The final application.properties should look like\u00a0this:</p>\n<pre>spring.datasource.url=jdbc:mysql://localhost:3306/postcodes?createDatabaseIfNotExist=true<br>spring.datasource.username=root<br>spring.jpa.hibernate.ddl-auto=update<br>spring.jpa.defer-datasource-initialization=true<br>spring.sql.init.mode=always</pre>\n<p>Now run your application. Go to MySQL Workbench and check if database called \u2018employees\u2019 exist. Check if there is a table in there (table name will be the one you defined in your Entity component). Open the table and behold it contains the dummy\u00a0data!</p>\n<pre>SHOW DATABASES;<br>USE employees;<br>SHOW TABLES;<br>SELECT * FROM employees;</pre>\n<p>Now you are ready to test your application with a dummy data without worrying about adding data\u00a0first.</p>\n<p>If you want to see the complete app it is <a href=\"https://github.com/Mariya-ghafoor/employee-creator-backend\">here</a> on my\u00a0Github.</p>\n<p>If you liked this tutorial please give a clap and follow me for\u00a0more.</p>\n<img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=96d06fa99cc9\" width=\"1\" height=\"1\" alt=\"\"><hr>\n<p><a href=\"https://towardsdev.com/create-and-initialise-database-automatically-in-spring-boot-96d06fa99cc9\">Create and initialize database automatically in Spring Boot</a> was originally published in <a href=\"https://towardsdev.com/\">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>\n","content":"\n<figure><img alt=\"Data is king\" src=\"https://cdn-images-1.medium.com/max/1024/1*GZQy1YhGdCMFLv5GoWQrRQ.png\"></figure><p>If you are working with a database in Spring boot the chances are you will need some initial data in the database for testing purpose. You may not want to manually create database and then send POST requests to enter values in your\u00a0tables.</p>\n<p>Spring boot makes it very easy to automate the whole process. From creating database, creating tables and filling them with initial data all could be done automatically when you start your spring boot\u00a0app.</p>\n<p>In this tutorial I will go through each step of database initialization.</p>\n<p><strong>Prerequisites</strong>: Basic knowledge of Spring boot with the ability to create a basic REST API. I will be working with a MySql database but you can use others. The process will remain the\u00a0same.</p>\n<h3><strong>Database Initialization in Spring\u00a0boot</strong></h3>\n<h3><strong>Step 1: Create\u00a0Database</strong></h3>\n<p>To tell Spring to create database as soon as your app runs add the following to your application.properties file:</p>\n<pre>spring.datasource.url=jdbc:mysql://localhost:3306/employees?createDatabaseIfNotExist=true<br>spring.datasource.username=root<br>spring.jpa.hibernate.ddl-auto=update</pre>\n<p>Replace \u2018<em>employees</em>\u2019 with the name of your database and \u20183306\u2019 with the port on which server is running. If you want you can specify the port by adding this property:</p>\n<pre>server.port=3306</pre>\n<h3><strong>Step 2: Create\u00a0Data.sql</strong></h3>\n<p>Now we need to create a file called Data.sql which will contain commands to fill our database. When the app runs Data.sql runs\u00a0first.</p>\n<blockquote>Remember! Always add Data.sql to your classpath which means it should be where your application.properties is i.e. in the <strong>resources</strong> folder.</blockquote>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/353/1*fxl1j7EKJOPTkB7Si3np1g.png\"><figcaption>data.sql should be in the resources folder</figcaption></figure><p>Now the question is how do we create data.sql? To create data.sql which will populate your database head to <a href=\"https://filldb.info/\">https://filldb.info/</a>\u00a0.</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*AROJvLd5Cdr84zuc6pM8Uw.png\"><figcaption>filldb.info</figcaption></figure><p>First we need to create a schema. Click <strong>Database Generator</strong>.</p>\n<p>Click New Table. Provide table name and fields. In my case table name was \u2018employees\u2019 and fields were \u2018firstName\u2019, \u2018lastName\u2019 and \u2018email\u2019. Then click \u2018Save table\u2019. Next click \u2018Generate Data\u2019 and choose your\u00a0table.</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*_4sy-Z3Tx5oSmyATwcM5jg.png\"></figure><p>Next click \u2018Generate data\u2019 and voila you have 100 rows of fake data that you can now export to your Spring boot\u00a0project.</p>\n<p>Click \u2018Export Employees\u2019 and rename the downloaded file as data.sql. Copy it to your resources folder.</p>\n<h3><strong>Step 3: Fill the\u00a0Database</strong></h3>\n<p>Now we need to add the following two properties to our application.properties:</p>\n<pre>spring.sql.init.mode=always<br>spring.jpa.defer-datasource-initialization=true</pre>\n<p>The first property will tell Spring to look for a sql file to initializa database.</p>\n<p>The second property will defer the loading of data.sql until Hibernate creates tables that are defined by our Entity component. We can also provide our own schema through schema.sql but we will not do that in this tutorial. Instead we will leave it to Hibernate to do that for\u00a0us.</p>\n<blockquote>In simple terms Hibernate is a tool to map Java objects to relational databases</blockquote>\n<p>The final application.properties should look like\u00a0this:</p>\n<pre>spring.datasource.url=jdbc:mysql://localhost:3306/postcodes?createDatabaseIfNotExist=true<br>spring.datasource.username=root<br>spring.jpa.hibernate.ddl-auto=update<br>spring.jpa.defer-datasource-initialization=true<br>spring.sql.init.mode=always</pre>\n<p>Now run your application. Go to MySQL Workbench and check if database called \u2018employees\u2019 exist. Check if there is a table in there (table name will be the one you defined in your Entity component). Open the table and behold it contains the dummy\u00a0data!</p>\n<pre>SHOW DATABASES;<br>USE employees;<br>SHOW TABLES;<br>SELECT * FROM employees;</pre>\n<p>Now you are ready to test your application with a dummy data without worrying about adding data\u00a0first.</p>\n<p>If you want to see the complete app it is <a href=\"https://github.com/Mariya-ghafoor/employee-creator-backend\">here</a> on my\u00a0Github.</p>\n<p>If you liked this tutorial please give a clap and follow me for\u00a0more.</p>\n<img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=96d06fa99cc9\" width=\"1\" height=\"1\" alt=\"\"><hr>\n<p><a href=\"https://towardsdev.com/create-and-initialise-database-automatically-in-spring-boot-96d06fa99cc9\">Create and initialize database automatically in Spring Boot</a> was originally published in <a href=\"https://towardsdev.com/\">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>\n","enclosure":{},"categories":["spring-boot","database","mysql","java","hibernate"]},{"title":"Why is my React component not receiving updated props?","pubDate":"2023-12-18 01:49:10","link":"https://medium.com/@mariya.aghafoor/why-is-my-react-component-not-receiving-updated-props-370f726d3791?source=rss-c5df4976ed9f------2","guid":"https://medium.com/p/370f726d3791","author":"Mariya Abdul Ghafoor","thumbnail":"","description":"\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/400/1*PWe4DmAE78BLD4SHpXizMw.png\"><figcaption>React js</figcaption></figure><p>React is a popular Javascript library that is famous for fast and efficient rendering. Its idiosyncrasies often leave developers scratching their\u00a0head.</p>\n<p>One of the more common problems that the developers face is that the props in child component do not change even when they have updated in parent component. Take the following example where we are fetching data in the parent component and passing it to the child which then performs some processing on the\u00a0data.</p>\n<p>Parent component</p>\n<pre>const Parent = () =&gt; {<br>const [data, setData] = useState([]); <br><br>const getUsers = () =&gt; {<br>// some logic to get users from server<br>setData(users); //after receieving users from the server set data state<br>}<br><br>useEffect(()=&gt;{<br>getUsers(); <br><br>},[])<br><br>return(<br>      &lt;Child data={data}/&gt; // pass the data props to the child     <br>}<br>export default Parent;</pre>\n<p>Child component</p>\n<pre>const Child = (props) =&gt; {<br><br>useEffect(()=&gt;{<br>console.log(props) //this will show old props even after they have changed<br>//do something with props<br>},[])<br>}</pre>\n<p><strong>Why is React not updating the props in\u00a0child?</strong></p>\n<p>From React official\u00a0<a href=\"https://react.dev/learn/passing-props-to-a-component\">docs</a>:</p>\n<blockquote>Props are immutable\u200a\u2014\u200aa term from computer science meaning \u201cunchangeable\u201d. When a component needs to change its props (for example, in response to a user interaction or new data), it will have to \u201cask\u201d its parent component to pass it different props\u200a\u2014\u200aa new object! Its old props will then be cast aside, and eventually the JavaScript engine will reclaim the memory taken by\u00a0them.</blockquote>\n<p><strong>So how does the child \u2018ask\u2019 the parent for new\u00a0props?</strong></p>\n<p>Simply by adding props in the dependency array of useEffect hook like\u00a0this:</p>\n<pre>const Child = (props) =&gt; {<br><br>useEffect(()=&gt;{<br>console.log(props) //this will show old props even after they have changed<br>//do something with props<br>},[props])<br>}</pre>\n<p>Now every time the props change the useEffect will force a re-render which will force the parent to pass down the new\u00a0props.</p>\n<img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=370f726d3791\" width=\"1\" height=\"1\" alt=\"\">\n","content":"\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/400/1*PWe4DmAE78BLD4SHpXizMw.png\"><figcaption>React js</figcaption></figure><p>React is a popular Javascript library that is famous for fast and efficient rendering. Its idiosyncrasies often leave developers scratching their\u00a0head.</p>\n<p>One of the more common problems that the developers face is that the props in child component do not change even when they have updated in parent component. Take the following example where we are fetching data in the parent component and passing it to the child which then performs some processing on the\u00a0data.</p>\n<p>Parent component</p>\n<pre>const Parent = () =&gt; {<br>const [data, setData] = useState([]); <br><br>const getUsers = () =&gt; {<br>// some logic to get users from server<br>setData(users); //after receieving users from the server set data state<br>}<br><br>useEffect(()=&gt;{<br>getUsers(); <br><br>},[])<br><br>return(<br>      &lt;Child data={data}/&gt; // pass the data props to the child     <br>}<br>export default Parent;</pre>\n<p>Child component</p>\n<pre>const Child = (props) =&gt; {<br><br>useEffect(()=&gt;{<br>console.log(props) //this will show old props even after they have changed<br>//do something with props<br>},[])<br>}</pre>\n<p><strong>Why is React not updating the props in\u00a0child?</strong></p>\n<p>From React official\u00a0<a href=\"https://react.dev/learn/passing-props-to-a-component\">docs</a>:</p>\n<blockquote>Props are immutable\u200a\u2014\u200aa term from computer science meaning \u201cunchangeable\u201d. When a component needs to change its props (for example, in response to a user interaction or new data), it will have to \u201cask\u201d its parent component to pass it different props\u200a\u2014\u200aa new object! Its old props will then be cast aside, and eventually the JavaScript engine will reclaim the memory taken by\u00a0them.</blockquote>\n<p><strong>So how does the child \u2018ask\u2019 the parent for new\u00a0props?</strong></p>\n<p>Simply by adding props in the dependency array of useEffect hook like\u00a0this:</p>\n<pre>const Child = (props) =&gt; {<br><br>useEffect(()=&gt;{<br>console.log(props) //this will show old props even after they have changed<br>//do something with props<br>},[props])<br>}</pre>\n<p>Now every time the props change the useEffect will force a re-render which will force the parent to pass down the new\u00a0props.</p>\n<img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=370f726d3791\" width=\"1\" height=\"1\" alt=\"\">\n","enclosure":{},"categories":["react-hook","javascript","react-props","reactjs","react-hook-useeffect"]},{"title":"What the heck is REST API???","pubDate":"2023-11-13 10:50:35","link":"https://medium.com/@mariya.aghafoor/what-the-heck-is-rest-api-490c3c2dc8a2?source=rss-c5df4976ed9f------2","guid":"https://medium.com/p/490c3c2dc8a2","author":"Mariya Abdul Ghafoor","thumbnail":"","description":"\n<p>If you are like me you would have been having much trouble understanding what exactly is a REST API? Fear not as I am here to rescue you from the monster called\u00a0REST.</p>\n<p><strong>API\u200a\u2014\u200aAPPLICATION PROGRAMMING INTERFACE</strong></p>\n<p>Before understanding what REST is we should be clear on what an API is. An Application Programming Interface is a way for two applications to interact with each\u00a0other.</p>\n<p>Let\u2019s take an example. You are designing a tracking system that tracks a user and displays their location on maps. Now instead of reinventing the wheel you would want to use Google maps to display user location. Here comes the Google Maps API. You will request the API to send you back the tracking information and in your request you would provide the user location.</p>\n<p>Now if you were Google you would want to design your API in a way that is fast, efficient, easily scalable and reliable. Here comes\u00a0REST.</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*S9YXC5uJcz37_EGfh9HP1A.png\"><figcaption>Client server communication in REST- Image from AltexSoft</figcaption></figure><p><strong>REST\u200a\u2014\u200aREPRESENTATIONAL STATE\u00a0TRANSFER</strong></p>\n<p>REST is not a design pattern, it is a software architecture. It conditions how an API should work so that it can provide an efficient reliable way of communication.</p>\n<p>The information that an API following REST aechitecture serves is called a \u2018representation\u2019. A REST API should fulfill the following design constraints:</p>\n<ol><li><strong>Uniformity</strong></li></ol>\n<p>A client makes a request to a server for some information. In our above example our website would the client while Google Maps would be the server. When the information comes back it should be in a standard format. This format could be different from how the server actually stores information on its\u00a0end.</p>\n<p><strong>2. Statelessness</strong></p>\n<p>Every request that a client makes is stateless or independent of the other requests. This statelessness requires a REST API to send all the information every time a new request is\u00a0made.</p>\n<p><strong>3. Cachebility</strong></p>\n<p>Sending all the information every time a call is made means a lot of data transfer which can make an API slow. This is avoided in REST by allowing cacheing of information on client side. Each API response define itself as cacheable or noncacheable.</p>\n<p><strong>4. Code on\u00a0demand</strong></p>\n<p>A REST API can send code as part of the response to extend functionality on the client side. For example when you fill a form you get a response which says the password should be of a certain length\u00a0etc.</p>\n<p><strong>5. Layers</strong></p>\n<p>A REST API can have many layers. It can be run on different servers handling secuirty or providing business logic for example. This provides greater flexibility and scalibilty as each layer can be modified separately.</p>\n<p><strong>DISADVANTAGES OF REST\u00a0APIs</strong></p>\n<p>One disadvantage of REST is that you cannot maintain state which means you need to send complete information within different sessions.</p>\n<p><strong>Conclusion</strong></p>\n<p>So that is what the REST is. Not a ghost but just a way to design APIs. It makes our APIs modular, flexible and more efficient.</p>\n<img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=490c3c2dc8a2\" width=\"1\" height=\"1\" alt=\"\">\n","content":"\n<p>If you are like me you would have been having much trouble understanding what exactly is a REST API? Fear not as I am here to rescue you from the monster called\u00a0REST.</p>\n<p><strong>API\u200a\u2014\u200aAPPLICATION PROGRAMMING INTERFACE</strong></p>\n<p>Before understanding what REST is we should be clear on what an API is. An Application Programming Interface is a way for two applications to interact with each\u00a0other.</p>\n<p>Let\u2019s take an example. You are designing a tracking system that tracks a user and displays their location on maps. Now instead of reinventing the wheel you would want to use Google maps to display user location. Here comes the Google Maps API. You will request the API to send you back the tracking information and in your request you would provide the user location.</p>\n<p>Now if you were Google you would want to design your API in a way that is fast, efficient, easily scalable and reliable. Here comes\u00a0REST.</p>\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*S9YXC5uJcz37_EGfh9HP1A.png\"><figcaption>Client server communication in REST- Image from AltexSoft</figcaption></figure><p><strong>REST\u200a\u2014\u200aREPRESENTATIONAL STATE\u00a0TRANSFER</strong></p>\n<p>REST is not a design pattern, it is a software architecture. It conditions how an API should work so that it can provide an efficient reliable way of communication.</p>\n<p>The information that an API following REST aechitecture serves is called a \u2018representation\u2019. A REST API should fulfill the following design constraints:</p>\n<ol><li><strong>Uniformity</strong></li></ol>\n<p>A client makes a request to a server for some information. In our above example our website would the client while Google Maps would be the server. When the information comes back it should be in a standard format. This format could be different from how the server actually stores information on its\u00a0end.</p>\n<p><strong>2. Statelessness</strong></p>\n<p>Every request that a client makes is stateless or independent of the other requests. This statelessness requires a REST API to send all the information every time a new request is\u00a0made.</p>\n<p><strong>3. Cachebility</strong></p>\n<p>Sending all the information every time a call is made means a lot of data transfer which can make an API slow. This is avoided in REST by allowing cacheing of information on client side. Each API response define itself as cacheable or noncacheable.</p>\n<p><strong>4. Code on\u00a0demand</strong></p>\n<p>A REST API can send code as part of the response to extend functionality on the client side. For example when you fill a form you get a response which says the password should be of a certain length\u00a0etc.</p>\n<p><strong>5. Layers</strong></p>\n<p>A REST API can have many layers. It can be run on different servers handling secuirty or providing business logic for example. This provides greater flexibility and scalibilty as each layer can be modified separately.</p>\n<p><strong>DISADVANTAGES OF REST\u00a0APIs</strong></p>\n<p>One disadvantage of REST is that you cannot maintain state which means you need to send complete information within different sessions.</p>\n<p><strong>Conclusion</strong></p>\n<p>So that is what the REST is. Not a ghost but just a way to design APIs. It makes our APIs modular, flexible and more efficient.</p>\n<img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=490c3c2dc8a2\" width=\"1\" height=\"1\" alt=\"\">\n","enclosure":{},"categories":["web-services","client-server","restful-api","rest-api","architecture"]},{"title":"Multithreading vs. Multiprocessing","pubDate":"2023-05-26 05:36:59","link":"https://medium.com/@mariya.aghafoor/multithreading-vs-multiprocessing-9b2103818474?source=rss-c5df4976ed9f------2","guid":"https://medium.com/p/9b2103818474","author":"Mariya Abdul Ghafoor","thumbnail":"","description":"\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*t4s3YQIpAcFC48nttPZTkA.png\"></figure><p>In the realm of computer programming, multithreading and multiprocessing are two essential concepts, each with its unique purpose and characteristics. Understanding their distinctions is crucial for developers seeking to optimize their applications\u2019 performance and responsiveness. To shed light on this topic, let\u2019s explore the dissimilarities between multithreading and multiprocessing through real-life examples.</p>\n<p><strong>Multithreading</strong>:</p>\n<blockquote>Multithreading involves the execution of multiple threads within a <em>single\u00a0process</em>.</blockquote>\n<p>Picture a bustling kitchen where a chef prepares multiple dishes simultaneously. Each dish represents a thread, and the chef represents the main process. While cooking pasta, the chef can simultaneously prepare a sauce, ensuring efficient resource utilization. However, if one dish encounters a problem, such as a burnt pan, it can affect the entire process, causing delays or\u00a0errors.</p>\n<p><strong>Multiprocessing</strong>:</p>\n<blockquote>Multiprocessing refers to the execution of <em>multiple processes</em> simultaneously, each running its own independent task.</blockquote>\n<p>Imagine a factory with multiple assembly lines. Each assembly line operates autonomously, assembling different products concurrently. This approach allows for increased throughput and fault isolation. If a problem occurs on one assembly line, the others remain unaffected, maintaining overall productivity.</p>\n<p><strong>Key Differences:</strong></p>\n<p><strong>1. Communication and Resource\u00a0Sharing</strong>:</p>\n<p>In multithreading, threads share the <strong>same memory space</strong>, allowing for quick communication but requiring careful synchronization. In multiprocessing, processes have <strong>separate memory spaces</strong> and communicate through inter-process communication mechanisms, such as pipes or message\u00a0queues.</p>\n<p><strong>2. Fault Isolation:</strong></p>\n<p>Multithreading can be <strong>prone to errors</strong> since one problematic thread can potentially crash the entire process. On the other hand, multiprocessing offers better <strong>fault isolation</strong>, as issues in one process usually don\u2019t impact\u00a0others.</p>\n<p><strong>3. Utilization of Resources:</strong></p>\n<p>Multithreading is efficient when tasks are IO-bound or <strong>require extensive coordination</strong>, as it avoids the overhead of creating and managing multiple processes. Multiprocessing is beneficial for CPU-bound tasks, where <strong>distributing the workload</strong> across multiple processors can lead to improved performance.</p>\n<p><strong>Conclusion</strong>:<br>Multithreading and multiprocessing present distinctive approaches to achieving concurrency in software applications.</p>\n<blockquote>Multithreading enables efficient utilization of resources but demands careful synchronization and can suffer from a lack of fault isolation. Multiprocessing, with its independent processes and fault isolation, excels in scenarios requiring enhanced reliability and performance, particularly for CPU-bound tasks.</blockquote>\n<p>As a developer, understanding the nuances of multithreading and multiprocessing empowers you to make informed decisions in designing concurrent applications for optimal efficiency and responsiveness.</p>\n<img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=9b2103818474\" width=\"1\" height=\"1\" alt=\"\">\n","content":"\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*t4s3YQIpAcFC48nttPZTkA.png\"></figure><p>In the realm of computer programming, multithreading and multiprocessing are two essential concepts, each with its unique purpose and characteristics. Understanding their distinctions is crucial for developers seeking to optimize their applications\u2019 performance and responsiveness. To shed light on this topic, let\u2019s explore the dissimilarities between multithreading and multiprocessing through real-life examples.</p>\n<p><strong>Multithreading</strong>:</p>\n<blockquote>Multithreading involves the execution of multiple threads within a <em>single\u00a0process</em>.</blockquote>\n<p>Picture a bustling kitchen where a chef prepares multiple dishes simultaneously. Each dish represents a thread, and the chef represents the main process. While cooking pasta, the chef can simultaneously prepare a sauce, ensuring efficient resource utilization. However, if one dish encounters a problem, such as a burnt pan, it can affect the entire process, causing delays or\u00a0errors.</p>\n<p><strong>Multiprocessing</strong>:</p>\n<blockquote>Multiprocessing refers to the execution of <em>multiple processes</em> simultaneously, each running its own independent task.</blockquote>\n<p>Imagine a factory with multiple assembly lines. Each assembly line operates autonomously, assembling different products concurrently. This approach allows for increased throughput and fault isolation. If a problem occurs on one assembly line, the others remain unaffected, maintaining overall productivity.</p>\n<p><strong>Key Differences:</strong></p>\n<p><strong>1. Communication and Resource\u00a0Sharing</strong>:</p>\n<p>In multithreading, threads share the <strong>same memory space</strong>, allowing for quick communication but requiring careful synchronization. In multiprocessing, processes have <strong>separate memory spaces</strong> and communicate through inter-process communication mechanisms, such as pipes or message\u00a0queues.</p>\n<p><strong>2. Fault Isolation:</strong></p>\n<p>Multithreading can be <strong>prone to errors</strong> since one problematic thread can potentially crash the entire process. On the other hand, multiprocessing offers better <strong>fault isolation</strong>, as issues in one process usually don\u2019t impact\u00a0others.</p>\n<p><strong>3. Utilization of Resources:</strong></p>\n<p>Multithreading is efficient when tasks are IO-bound or <strong>require extensive coordination</strong>, as it avoids the overhead of creating and managing multiple processes. Multiprocessing is beneficial for CPU-bound tasks, where <strong>distributing the workload</strong> across multiple processors can lead to improved performance.</p>\n<p><strong>Conclusion</strong>:<br>Multithreading and multiprocessing present distinctive approaches to achieving concurrency in software applications.</p>\n<blockquote>Multithreading enables efficient utilization of resources but demands careful synchronization and can suffer from a lack of fault isolation. Multiprocessing, with its independent processes and fault isolation, excels in scenarios requiring enhanced reliability and performance, particularly for CPU-bound tasks.</blockquote>\n<p>As a developer, understanding the nuances of multithreading and multiprocessing empowers you to make informed decisions in designing concurrent applications for optimal efficiency and responsiveness.</p>\n<img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=9b2103818474\" width=\"1\" height=\"1\" alt=\"\">\n","enclosure":{},"categories":[]},{"title":"Python\u2019s Fusion of Compilation and Interpretation for Powerful Execution","pubDate":"2023-05-16 13:40:03","link":"https://medium.com/@mariya.aghafoor/pythons-fusion-of-compilation-and-interpretation-for-powerful-execution-a562efb2471f?source=rss-c5df4976ed9f------2","guid":"https://medium.com/p/a562efb2471f","author":"Mariya Abdul Ghafoor","thumbnail":"","description":"\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*dbT0T6bLexF5nYgAViRvcQ.png\"></figure><p>Python\u2019s execution model harmoniously combines the strengths of both compilation and interpretation, resulting in a versatile and efficient programming language. This synergistic approach enhances development productivity and runtime performance. Let\u2019s delve into the intricacies of Python\u2019s blend, exemplified by a Python code snippet and its corresponding bytecode representation.</p>\n<p><strong>Example</strong>: Consider the following Python\u00a0code:</p>\n<pre>def calculate_sum(a, b):<br>    result = a + b<br>    print(\"The sum is:\", result)<br><br>calculate_sum(3, 5)</pre>\n<p>The bytecode generated for this code would resemble:</p>\n<pre>  2           0 LOAD_FAST                0 (a)<br>              2 LOAD_FAST                1 (b)<br>              4 BINARY_ADD<br>              6 STORE_FAST               2 (result)<br><br>  3           8 LOAD_GLOBAL              0 (print)<br>             10 LOAD_CONST               1 ('The sum is:')<br>             12 LOAD_FAST                2 (result)<br>             14 CALL_FUNCTION            2<br>             16 POP_TOP<br>             18 LOAD_CONST               0 (None)<br>             20 RETURN_VALUE</pre>\n<p><strong>Python\u2019s Compilation and Interpretation Dance:</strong></p>\n<p>Python first undergoes a compilation phase where the source code is transformed into bytecode, resembling an architectural blueprint for the subsequent execution. This bytecode is then interpreted by the Python interpreter, line by line, executing the corresponding operations in a dynamic and efficient manner.</p>\n<p>The compilation step optimizes the code structure and provides platform independence, while the interpretation step allows for interactive development and runtime adaptability. Python\u2019s Just-In-Time (JIT) compilation further enhances performance by dynamically optimizing critical code sections during execution.</p>\n<p><strong>How this helps Python in Web Development:</strong></p>\n<p>One example where Python\u2019s use of both compilation and interpretation proves beneficial is in the domain of web development. Let\u2019s consider a scenario where a web application is built using Python, utilizing frameworks like Django or\u00a0Flask.</p>\n<p>During development, Python\u2019s interpretive nature comes into play. Developers can make changes to the code, such as adding new features or modifying existing functionality, and immediately see the results without the need for a separate compilation step. This interactive development process allows for quick iterations, making it easier to test and refine the application.</p>\n<p>On the other hand, when it comes to deploying the web application in a production environment, Python\u2019s compilation aspect shines. The source code is compiled into bytecode, optimizing the performance and reducing startup time. The compiled bytecode can be cached, allowing subsequent requests to be processed more efficiently. This compilation step ensures that the web application performs optimally, even under high traffic conditions.</p>\n<p><strong>Conclusion</strong>:</p>\n<p>By combining compilation and interpretation, Python provides the best of both worlds in web development. Developers can enjoy the agility of interpretation during the development phase, while users benefit from the optimized execution offered by the compiled bytecode in the production environment. This dual approach enhances productivity, responsiveness, and scalability, making Python an excellent choice for building dynamic and efficient web applications.</p>\n<img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=a562efb2471f\" width=\"1\" height=\"1\" alt=\"\">\n","content":"\n<figure><img alt=\"\" src=\"https://cdn-images-1.medium.com/max/1024/1*dbT0T6bLexF5nYgAViRvcQ.png\"></figure><p>Python\u2019s execution model harmoniously combines the strengths of both compilation and interpretation, resulting in a versatile and efficient programming language. This synergistic approach enhances development productivity and runtime performance. Let\u2019s delve into the intricacies of Python\u2019s blend, exemplified by a Python code snippet and its corresponding bytecode representation.</p>\n<p><strong>Example</strong>: Consider the following Python\u00a0code:</p>\n<pre>def calculate_sum(a, b):<br>    result = a + b<br>    print(\"The sum is:\", result)<br><br>calculate_sum(3, 5)</pre>\n<p>The bytecode generated for this code would resemble:</p>\n<pre>  2           0 LOAD_FAST                0 (a)<br>              2 LOAD_FAST                1 (b)<br>              4 BINARY_ADD<br>              6 STORE_FAST               2 (result)<br><br>  3           8 LOAD_GLOBAL              0 (print)<br>             10 LOAD_CONST               1 ('The sum is:')<br>             12 LOAD_FAST                2 (result)<br>             14 CALL_FUNCTION            2<br>             16 POP_TOP<br>             18 LOAD_CONST               0 (None)<br>             20 RETURN_VALUE</pre>\n<p><strong>Python\u2019s Compilation and Interpretation Dance:</strong></p>\n<p>Python first undergoes a compilation phase where the source code is transformed into bytecode, resembling an architectural blueprint for the subsequent execution. This bytecode is then interpreted by the Python interpreter, line by line, executing the corresponding operations in a dynamic and efficient manner.</p>\n<p>The compilation step optimizes the code structure and provides platform independence, while the interpretation step allows for interactive development and runtime adaptability. Python\u2019s Just-In-Time (JIT) compilation further enhances performance by dynamically optimizing critical code sections during execution.</p>\n<p><strong>How this helps Python in Web Development:</strong></p>\n<p>One example where Python\u2019s use of both compilation and interpretation proves beneficial is in the domain of web development. Let\u2019s consider a scenario where a web application is built using Python, utilizing frameworks like Django or\u00a0Flask.</p>\n<p>During development, Python\u2019s interpretive nature comes into play. Developers can make changes to the code, such as adding new features or modifying existing functionality, and immediately see the results without the need for a separate compilation step. This interactive development process allows for quick iterations, making it easier to test and refine the application.</p>\n<p>On the other hand, when it comes to deploying the web application in a production environment, Python\u2019s compilation aspect shines. The source code is compiled into bytecode, optimizing the performance and reducing startup time. The compiled bytecode can be cached, allowing subsequent requests to be processed more efficiently. This compilation step ensures that the web application performs optimally, even under high traffic conditions.</p>\n<p><strong>Conclusion</strong>:</p>\n<p>By combining compilation and interpretation, Python provides the best of both worlds in web development. Developers can enjoy the agility of interpretation during the development phase, while users benefit from the optimized execution offered by the compiled bytecode in the production environment. This dual approach enhances productivity, responsiveness, and scalability, making Python an excellent choice for building dynamic and efficient web applications.</p>\n<img src=\"https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=a562efb2471f\" width=\"1\" height=\"1\" alt=\"\">\n","enclosure":{},"categories":[]}]}