<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Rakesh Sagar</title>
    <description>The latest articles on Forem by Rakesh Sagar (@rakeshsagar64).</description>
    <link>https://forem.com/rakeshsagar64</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F259486%2F713b6934-ca54-4b5a-9dc4-a0e0fa791533.png</url>
      <title>Forem: Rakesh Sagar</title>
      <link>https://forem.com/rakeshsagar64</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rakeshsagar64"/>
    <language>en</language>
    <item>
      <title>[TIL] A better response to post request (Spring Boot)</title>
      <dc:creator>Rakesh Sagar</dc:creator>
      <pubDate>Mon, 07 Nov 2022 04:55:23 +0000</pubDate>
      <link>https://forem.com/rakeshsagar64/til-a-better-response-to-post-request-spring-boot-3dn</link>
      <guid>https://forem.com/rakeshsagar64/til-a-better-response-to-post-request-spring-boot-3dn</guid>
      <description>&lt;p&gt;When writing an api that saves the data it would be nice if there was a way to see the the data stored. So usually the id is returned in the response of the api. &lt;br&gt;
 Spring Boot provides a better way to handle this, By providing the created method in response entity which accepts a url as an argument and returns 201 as he response status.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ResponseEntity.created(
  URI.create("http://domainname/getEndpoint/"+entity.getId())
).build();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This would apply a response header called &lt;strong&gt;Location&lt;/strong&gt; with the above mentioned url.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ro0nllG_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mkvw0dtwpcnib5e40mbd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ro0nllG_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mkvw0dtwpcnib5e40mbd.png" alt="Image description" width="880" height="206"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, we want to make the domain name dynamic as the api can be deployed in multiple environments.&lt;br&gt;
A quick google search led me to this Stack Overflow Answer&lt;/p&gt;
&lt;div class="ltag__stackexchange--container"&gt;
  &lt;div class="ltag__stackexchange--title-container"&gt;
    
      &lt;div class="ltag__stackexchange--title"&gt;
        &lt;div class="ltag__stackexchange--header"&gt;
          &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7Gn-iPj_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackoverflow-logo-b42691ae545e4810b105ee957979a853a696085e67e43ee14c5699cf3e890fb4.svg" alt=""&gt;
          &lt;a href="https://stackoverflow.com/questions/1490821/whats-the-best-way-to-get-the-current-url-in-spring-mvc" rel="noopener noreferrer"&gt;
            What's the best way to get the current URL in Spring MVC?
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="ltag__stackexchange--post-metadata"&gt;
          &lt;span&gt;Sep 29 '09&lt;/span&gt;
            &lt;span&gt;Comments: 1&lt;/span&gt;
            &lt;span&gt;Answers: 7&lt;/span&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;a class="ltag__stackexchange--score-container" href="https://stackoverflow.com/questions/1490821/whats-the-best-way-to-get-the-current-url-in-spring-mvc" rel="noopener noreferrer"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y9mJpuJP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackexchange-arrow-up-eff2e2849e67d156181d258e38802c0b57fa011f74164a7f97675ca3b6ab756b.svg" alt=""&gt;
        &lt;div class="ltag__stackexchange--score-number"&gt;
          119
        &lt;/div&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wif5Zq3z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/stackexchange-arrow-down-4349fac0dd932d284fab7e4dd9846f19a3710558efde0d2dfd05897f3eeb9aba.svg" alt=""&gt;
      &lt;/a&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--body"&gt;
    
&lt;p&gt;I'd like to create URLs based on the URL used by the client for the active request. Is there anything smarter than taking the current &lt;code&gt;HttpServletRequest&lt;/code&gt; object and it's &lt;code&gt;getParameter...()&lt;/code&gt; methods to rebuilt the complete URL including (and only) it's GET parameters.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Clarification: If possible I want to resign from&lt;/strong&gt;…&lt;/p&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--btn--container"&gt;
    &lt;a href="https://stackoverflow.com/questions/1490821/whats-the-best-way-to-get-the-current-url-in-spring-mvc" class="ltag__stackexchange--btn" rel="noopener noreferrer"&gt;Open Full Question&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;Here is the code snippet for that&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;URI uri = ServletUriComponentsBuilder
             .fromCurrentContextPath()
         .path("/get/{id}")
             .build(String.valueOf(entity.getId()));

return ResponseEntity.created(uri).build();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and the final response&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SvGWcy2A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wwyxru20wv9np8mspxg3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SvGWcy2A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wwyxru20wv9np8mspxg3.png" alt="Image description" width="880" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion (da ta daaa)&lt;/strong&gt; So after almost a year I posted here again. Any form of constructive critisism is always welcome with open arms. So.. see you around I guess ${insert akward goodbye}.&lt;/p&gt;

</description>
      <category>java</category>
      <category>todayilearned</category>
      <category>webdev</category>
      <category>api</category>
    </item>
    <item>
      <title>[TIL] More Mysql Stuff</title>
      <dc:creator>Rakesh Sagar</dc:creator>
      <pubDate>Fri, 10 Sep 2021 18:29:30 +0000</pubDate>
      <link>https://forem.com/rakeshsagar64/til-mysql-bits-5lk</link>
      <guid>https://forem.com/rakeshsagar64/til-mysql-bits-5lk</guid>
      <description>&lt;p&gt;1) You can get the create statement that was used to create a &lt;br&gt;
   table with the query&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;    &lt;span class="k"&gt;SHOW&lt;/span&gt; &lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="k"&gt;table_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2) JSON type in mysql an can be created by the query&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="k"&gt;table_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;col_name&lt;/span&gt; &lt;span class="n"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(obligatory crud tutorial coming soon)&lt;/p&gt;

&lt;p&gt;3) MySQL has ENUM datatype which can be used to store flag values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="k"&gt;table_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;status_flag&lt;/span&gt; &lt;span class="nb"&gt;ENUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'success'&lt;/span&gt; &lt;span class="s1"&gt;'failed'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is better than storing string values as enums are indexed by the database.&lt;/p&gt;

&lt;p&gt;4) using markdown text editor of this site.(It's pretty cool actually).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion (da ta daaa)&lt;/strong&gt; this flimsy article was written so that i don't break the habit of writing flimsy articles. Any form of constructive criticism is always welcome with open arms. So.. see you around i guess ${insert awkward goodbye}.&lt;/p&gt;

</description>
      <category>todayilearned</category>
      <category>mysql</category>
    </item>
    <item>
      <title>[TIL] Mysql Stuff</title>
      <dc:creator>Rakesh Sagar</dc:creator>
      <pubDate>Thu, 09 Sep 2021 19:44:23 +0000</pubDate>
      <link>https://forem.com/rakeshsagar64/til-mysql-stuff-3l9g</link>
      <guid>https://forem.com/rakeshsagar64/til-mysql-stuff-3l9g</guid>
      <description>&lt;p&gt;1) mysql has a json type and the subjectively less interesting spatial types (more r&amp;amp;d coming soon).&lt;/p&gt;

&lt;p&gt;2) mysql has a decimal type where you can specify exact number of digits. egs:- some_col DECIMAL(5,2); where 5 is the scale ie number of digits and 2 is the precision ie the number of digits after the decimal.&lt;/p&gt;

&lt;p&gt;3) the int column can be declared in these ways&lt;br&gt;
    ...int, ...&lt;br&gt;
    ...int(10), ... &lt;br&gt;
    ...int(10) unsigned, ...&lt;br&gt;
    ...int(10) unsigned zerofill, ...&lt;/p&gt;

&lt;p&gt;4) the '8' int(8) refers to the number of padding to the left of the number not the size/length of the number, and it becomes obvious when zerofill is added.Here is a screen shot i took just for you&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DPOer5BK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f1ljlhc69svvb5x463t8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DPOer5BK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f1ljlhc69svvb5x463t8.png" alt="Zerofill screen shot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5) Timestamp converts data into utc and back where as date time stores data as is.&lt;br&gt;
&lt;a href="https://www.c-sharpcorner.com/article/difference-between-mysql-datetime-and-timestamp-datatypes/"&gt;Here's a link to a post by someone who takes the chore of writing articles much more seriously.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion (da ta daaa)&lt;/strong&gt; this is first of (hopefully) many articles (atleast one per week). Any form of constructive critisism is always welcome with open arms. So.. see you around i guess ${insert akward goodbye}.&lt;/p&gt;

</description>
      <category>todayilearned</category>
      <category>mysql</category>
      <category>sql</category>
      <category>10sep2021</category>
    </item>
  </channel>
</rss>
