<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shivansh Saini on Medium]]></title>
        <description><![CDATA[Stories by Shivansh Saini on Medium]]></description>
        <link>https://medium.com/@shivanshs9?source=rss-e87333ba73ae------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*qQ9dbd_ia0nJxXZl.</url>
            <title>Stories by Shivansh Saini on Medium</title>
            <link>https://medium.com/@shivanshs9?source=rss-e87333ba73ae------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 08:43:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shivanshs9/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Do GitHub Action like a Pro!]]></title>
            <link>https://levelup.gitconnected.com/do-github-action-like-a-pro-594bcb813b22?source=rss-e87333ba73ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/594bcb813b22</guid>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[best-practices]]></category>
            <dc:creator><![CDATA[Shivansh Saini]]></dc:creator>
            <pubDate>Sat, 04 Jul 2020 08:46:25 GMT</pubDate>
            <atom:updated>2020-07-09T01:11:37.678Z</atom:updated>
            <content:encoded><![CDATA[<h4>Best CI/CD Practices</h4><h4>A set of best development practices you wish you’d known before publishing your first Action.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Tv7l1cHUf5kT1l27" /><figcaption>Photo by <a href="https://unsplash.com/@marcsm?utm_source=medium&amp;utm_medium=referral">Marc Sendra Martorell</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I don’t know about you, but software engineering interested me for its ability to automate stuff and let me be lazy. Most of the development that takes place now fundamentally automates one or the other services. However, anything at scale means there will be more tasks, as part of developer workflow, that would, only if automated, help speed up the rapid development.</p><p>No, even if it sounds a little bit similar, I’m not trying to be a <a href="https://www.nutanix.dev/2019/11/27/what-is-a-devops-advocate/">DevOps Advocate</a>, since that term’s interpretation is really quite varied and vast.</p><p>Now, when it comes to development workflow there’s quite a lot of stuff that could be automated, rather than just “build/test/package” cycle commonly provided by CI/CD services. And that’s why GitHub Actions is the perfect tool to handle it — since you’ve got code, documentation, issues, pull requests, code reviews, releases, and even <a href="https://github.com/features/packages">packages</a>, all in one place!</p><h3>tl;dr</h3><p>Hopefully, now that I’ve convinced you to at least give it a try and <a href="https://help.github.com/en/actions">read docs</a> with a cup of coffee ‘sides you, I ought to clear out one misconception —GitHub Actions are still pieces of code, and with every code ever written, it also comes with its own set of development practices to keep in mind.</p><p>And these recommended practices to build reusable Actions are the focus of this article. So, without further ado, let me clarify the scope of this article:</p><ul><li>Why publish Actions rather than writing bash/python/{insert scripting language} scripts?</li><li>Automating build and packaging of Action releases.</li><li>Automating proper versioning of your Action as per <a href="https://github.com/actions/toolkit/blob/master/docs/action-versioning.md#versioning">GitHub recommendations</a>.</li><li>Writing Tests! (you really didn’t think you’d get away without it, did you? :D)</li></ul><h3>Why use/publish Actions at all</h3><p>Automating a workflow requires programming each individual task of that workflow, which brings another unit to maintain an instrument. Even tasks as simple as installing build dependencies could suddenly fail and requires debugging. Then, what about complicated tasks like sending SMS alerts or publishing a release?</p><p>Sure, your team may program a shell or a python script for these tasks on their own, but that’s just asking for extra work to drag down the development considering long-term maintenance and stability.</p><p>Let’s discuss another situation where your team did manage to write and maintain such a script for one project and you find that there’s another project in need of programming a task with a similar use-case. Of course, to tackle that, you’d probably put that script in its own repo/gist and curl it wherever needed. Sounds like a hack? Yeah, I feel the same :).</p><p>Fortunately, GitHub realized a simple CI/CD workflow wouldn’t cut it, partly due to above-mentioned issues, and provided a <a href="https://github.com/marketplace?type=actions">Marketplace</a> to store and document all these reusable programs, called Actions, which are used as building-blocks of most workflows. That’s way, each job of workflow has a set of steps, where each step represents an individual task and can either run command or one of these Actions.</p><h3>Automating Build and packaging of Action releases.</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F1lxryzbQaqo49cKhCw%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2FSandiaLabs-robot-robotics-1lxryzbQaqo49cKhCw&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2F1lxryzbQaqo49cKhCw%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/b616e98218ae4d8be443ce5e1e2c2ef5/href">https://medium.com/media/b616e98218ae4d8be443ce5e1e2c2ef5/href</a></iframe><p>At first, I thought these Actions sounds similar to tons of libraries hosted at NPM for JS development, especially since GitHub runner completely supports Javascript Actions. However, there’s one major difference between Javascript Actions and NodeJS Library — <strong><em>package.json</em> is totally useless in the case of Actions</strong>. While writing npm scripts do come handy in the development of those Actions, GitHub Action only needs <em>action.yml </em>manifest file which describes the action name, inputs and main JS file to run. Heck, even the package version doesn’t matter since actions are used in workflows by specifying the commit ref (tag/branch/commit SHA).</p><p>Since the actions aren’t really packaged and stored in a central repository (unlike NPM), instead directly using GitHub to fetch the required action in a running job, they are really flexible to <a href="https://docs.github.com/en/actions/creating-actions/about-actions#choosing-a-location-for-your-action">store</a> and use in both public and private repositories. Although, I’ll focus only on storing the Action in its own repository, easing its maintenance, discovery, and release management.</p><p>As per <a href="https://docs.github.com/en/actions/creating-actions/about-actions#using-tags-for-release-management">GitHub recommendations</a>, we should use tags for their action releases. However, there’s a caveat here — running job fetches the Action source code, compressed as a tarball, of the commit pointed by that tag. That means the tagged commit should have a ready-to-use built code, the main JS, to run. But, isn’t it a known practice to never commit <a href="https://byjoeybaker.com/why-you-should-never-commit-node-modules-in-nodejs"><em>node_modules/</em></a> or <a href="https://kentcdodds.com/blog/why-i-dont-commit-generated-files-to-master/"><em>built </em>code</a> in VCS? Don’t we first commit <a href="https://www.toptal.com/developers/gitignore/"><em>.gitignore</em></a> as our first step in any new project?</p><p>Exploring a way to avoid committing the built code, I checked out official GitHub actions like <a href="https://github.com/actions/setup-go">setup-go</a>, but alas you can find that they did commit the built code, <a href="https://github.com/actions/setup-go/blob/master/dist/index.js"><em>dist/index.js</em></a>, though avoided committing <em>node_modules</em> by building only a single file using <a href="https://github.com/vercel/ncc">@zeit/ncc</a>. Nope, I can’t live with that hack, especially knowing that I can very well forget to run <em>npm run build </em>before committing (<a href="https://github.com/typicode/husky">husky</a> could solve that, though that would make my commit action a bit slow).</p><p>Exploring more actions, I liked the idea of “check in” the built code in its own release branch and then tag it, as used in <a href="https://github.com/engineerd/setup-kind">setup-kind action</a> (and documented in <a href="https://github.com/actions/typescript-action#publish-to-a-distribution-branch">official Action template</a>). While this is quite an elegant solution, I also realized that it still adds some manual tasks in my workflow… a perfect reason to use Github Actions to automate it!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9fea6aad649a6a8d57c95f63ccaa50d/href">https://medium.com/media/f9fea6aad649a6a8d57c95f63ccaa50d/href</a></iframe><p>I wrote this workflow which can be used as a template for your own Action release management needs. Let me first clarify some of my assumptions:</p><ol><li>Action is versioned as per <em>package.json</em>.</li><li><em>master</em> branch is protected and any push to it will have a different package version.</li><li>“Build package” step outputs the built code in the <em>dist/</em> folder and it doesn’t require <em>node_modules</em>.</li></ol><p>This way, one can reuse standard techniques used to version their Node library (like <a href="https://www.npmjs.com/package/semver">semver</a>) for JS Actions too.</p><p>The step named “Add &amp; Commit” force adds (since it’s in <em>.gitignore</em>) the built code in the <em>dist/ </em>folder, commits it a new release branch, “release/v&lt;version&gt;” and tag it appropriately.</p><p>The “release” job runs after the “build” job to create a new Release from the tag used in the previous job, hence elegantly managing both packaging and releasing.</p><p><strong>PS:</strong> There’s currently a GitHub bug that releases created by Action isn’t published to Marketplace, though these tags can still be used in workflows.</p><h3>Proper Versioning of your Action</h3><p>Most Dev projects take <a href="https://semver.org/">Semantic versioning</a> to heart and encourage developers to strike a balance between strict constraints and loose constraints, usually opting for a constraint flexible for patch releases as per <a href="https://jubianchi.github.io/semver-check/#/">semver</a>.</p><p>However, GitHub recommends to have a slightly different perspective when versioning your own Action in <a href="https://github.com/actions/toolkit/blob/master/docs/action-versioning.md#versioning">their doc</a>:</p><blockquote>Binding to a major version is the latest of that major version ( e.g. v1 == “1.*” )</blockquote><blockquote>Major versions should guarantee compatibility. A major version can add new capabilities but should not break existing input compatibility or break existing workflows.</blockquote><p>With major version binding, users can expect an Action’s major version to include necessary critical fixes and security patches, while still remaining compatible with their existing workflows. You should consider releasing a new major version whenever your changes affect compatibility.</p><p>GitHub suggests a <a href="https://github.com/actions/toolkit/blob/master/docs/action-versioning.md#recommendations">great way</a> to take the best of both worlds — semantic versioning and major version binding. Basically, follow semantic versioning practice and let the above workflow create a release on its own. Then with git, force create an <a href="http://alblue.bandlem.com/2011/04/git-tip-of-week-tags.html">annotated tag</a>, using the respective major version, to point to the released tag.</p><pre>git tag -fa v1 -m &quot;Update v1 tag&quot;<br>git push origin v1 --force</pre><p>Like you’ve probably guessed, there exists an Action to automate this laborious task too :D! You can use <a href="https://github.com/Actions-R-Us/actions-tagger">actions-tagger</a> to automatically keep your major versions up-to-date on any new release. Here’s a template workflow you can directly use:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6cdc4dfb1f652e41a044d04529bf2b9c/href">https://medium.com/media/6cdc4dfb1f652e41a044d04529bf2b9c/href</a></iframe><h3>Writing Tests!</h3><blockquote>“All code is guilty until proven innocent.”</blockquote><p>I hope you weren’t just planning to directly release untested code for your Action? :P<br>While it’s quite redundant at this point, as with any other piece of code, you should aim to write tests so it doesn’t just fail a valid workflow. Most actions use <a href="https://www.npmjs.com/package/jest">Jest</a> for their testing needs so I guess that’s sufficient.</p><p>I do have one tip — Do ensure only tested code gets merged into master, otherwise, you may have unwittingly created a new release that already failed the tests :P.</p><h3>Some Mindblowing Actions!</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FxT0xeJpnrWC4XWblEk%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fwhoa-hd-tim-and-eric-xT0xeJpnrWC4XWblEk&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2FxT0xeJpnrWC4XWblEk%2Fgiphy-downsized-large.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="289" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4342f52c56314fcb70fc40650749795/href">https://medium.com/media/f4342f52c56314fcb70fc40650749795/href</a></iframe><h4><a href="https://github.com/TriPSs/conventional-changelog-action">Conventional Changelog Action</a></h4><p>Having difficulty managing all the PRs and version bumps in a large project? Fret not, there’s an Action for that too! Assuming that your project is following <a href="https://www.conventionalcommits.org/en/v1.0.0/">Conventional Commits standard</a>,</p><h4><a href="https://github.com/machine-learning-apps/actions-chatops">ChatOps Action</a></h4><p>Ever wished there’s a bot stalking your repo’s issues listening for your commands to trigger some awesome actions? Yep, <a href="https://www.pagerduty.com/blog/what-is-chatops/">ChatOps</a> has invaded Github Actions too! :D</p><h3>Useful Links</h3><ul><li><a href="https://github.com/actions/typescript-action">Official JS Action template</a></li><li><a href="https://docs.github.com/en/actions/creating-actions/creating-a-javascript-action">Creating a JS Action</a></li></ul><h3>Ramblings</h3><p>I set out to pen all the learnings I acquired while creating my own Action, <a href="https://github.com/shivanshs9/setup-k8s-operator-sdk">setup-k8s-operator-sdk</a>. I did mess up some initial releases and so decided to document tips I wished I would’ve known before. Thanks for reading till the end, and I would love to hear some feedback and more useful tips!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=594bcb813b22" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/do-github-action-like-a-pro-594bcb813b22">Do GitHub Action like a Pro!</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hacking away an MVP in 24 hours]]></title>
            <link>https://medium.com/swlh/codefest19-hacking-mvp-ca7dcf329208?source=rss-e87333ba73ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca7dcf329208</guid>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[mvp]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[hackathons]]></category>
            <dc:creator><![CDATA[Shivansh Saini]]></dc:creator>
            <pubDate>Mon, 26 Aug 2019 20:48:08 GMT</pubDate>
            <atom:updated>2019-08-27T14:29:52.275Z</atom:updated>
            <content:encoded><![CDATA[<p>How I spent a weekend building a product from scratch with an awesome team and winning the hackathon!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hXNXQJ2pfjnI-A8sEl2xtA.jpeg" /><figcaption>Source: <a href="https://unsplash.com/photos/mpN7xjKQ_Ns">Unsplash</a></figcaption></figure><p>Do you know what’s more exciting than building an awesome product from scratch with your own hands? Doing it in 24 hours with an awesome team, mixed with lots of food and drinks! That’s how my friends and I spent our weekend at the <a href="https://codefest.tech/haxplore">CodeFest 2019 HaXplore</a> event — a 24-hour long hackathon event organized at our college. We were the team Traceback, a group of 3 people — <a href="https://github.com/Eerie16">Amritansh</a>, <a href="https://github.com/BAJUKA">Shravan</a> and <a href="https://shivanshs9.me/">me</a>. It was a most memorable experience; something which I really wanted to share with the help of my pen (technically, keyboard :D).</p><h3>tl;dr</h3><p>Jotting down some important points here as tips:</p><ul><li><strong>Focus on the judging criteria</strong> and ensure you’re finished with all the pre-requisites, before actually starting to code.</li><li><strong>Narrow down the idea</strong> so it can be visualized with just 2 line summary and satisfies the problem statement.</li><li>Avoid building something heavy, like an android app with such time constraints. <strong>Hackathons require fast iterations</strong> and last-minute working commits. Make sure your chosen platform can handle that!</li><li><strong>Never boast more than you can chew!</strong> The judging does get intensive sometimes, so make sure you know what you’ve implemented.</li><li><strong>Never lose out on your passion!</strong> To keep it driving, take breaks from code — enjoy the weather, take selfies, network with participants, have fun with the organizing team and <em>eat</em> (that’s the primary reason I attend hackathon).</li><li>Be confident in presentation and <strong>do your homework</strong>!</li></ul><p>Code: <a href="https://github.com/Eerie16/haxplore-traceback">https://github.com/Eerie16/haxplore-traceback</a><br>Website: <a href="http://agriconnect.ml/">http://agriconnect.ml/</a></p><h3>Ideation phase (24 hours to go)</h3><p>As we were told of our problem statement, I had my pen ready to jot down the 4 tracks we were given along with listing and then cutting out some hunches. After all, if these ideas came so easily to me, I can’t really not expect any other team to think of it too. We were also given AWS credits and informed beforehand that using AWS services rewards brownie points.<br>Soon enough, our team went to our desk and brainstormed over possible ideas. Since we had 4 different tracks to pick from, the sample space was really too vast. After thinking and dropping many ideas, we came down to a set of 3 and then chose one with the most impact, fulfilled all the brownie points and could be developed within the time constraint of 24 hours (technically, now less).<br>We called it <strong>FarmConnect</strong> at that time, btw — <em>a web app connecting and empowering farmers through digital technology and AI</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*NtDtFr5l8eCqUrG5" /></figure><h3>Coding Phase (23 hours to go)</h3><p>We listed out the requirements, planned our work distribution among us three and booted up our respective OSes! I started working on the ERD and the models sufficient for all the planned features. Using Django (well, it <em>is</em> for perfectionists with deadlines :D), I was done with all the models and authentication merged with the template and frontend work done by my teammate, Amritansh. Meanwhile, Shravan had finished with the AWS Lex Bot implementation and collected all the needed dataset.<br>After a needed break with some light snacks and a trivia quiz, two of us started crossing out the features due to implement and Shravan hacked away an ML model at Jupyter Notebook of AWS SageMaker. Time for Mid-Review now!</p><h3>Mid-Review (15 hours to go)</h3><p>Our Github Mentors discussed the idea and the product we’ve built so far. He liked the idea, but he raised a valid issue over two of the implemented features:</p><ul><li>we’ve been exposing user’s contact number to other logged-in users, which could lead to spam etc. Now that feature really required to bring out the communication between farmers, so we thought of an in-built chat.</li><li>scalability of our bot in its responses and the amount of knowledge it can have. Since we didn’t have a structured kind of data for it, we couldn’t think of any way to use it in a quality and scalable manner.</li></ul><p>So with two of our features down… what are we to do in the next 14-ish hours? Well, we pushed our concerns aside and went to have an awesome dinner of Pizzas and drinks!</p><h3>Coding Phase (13 hours to go)</h3><p>Well, we planned our next steps in the midst of the cool night breeze with our stomachs packed. First of all, I amped up my team’s confidence by mentioning that I can indeed complete the chat feature by morning. And that we’ll be focusing essentially on community and crowdsourced data, rather than some pesky bot. But to truly exhaust our options, Shravan did spend time on an API for bringing in the soil &amp; weather data, whereas Amritansh wrapped up all the other features. I essentially focused on the bidirectional chat thingy I need to implement — put up a bootstrap template in an iframe, switched to ASGI server and implemented essential Chat models (after an ERD, of course! :D).<br>I did have to put it on hold and spent time on exposing our built model to WWW using AWS Lambda functions and API gateways. After some annoying authentication token bugs, the request passed using Postman. <br>In 4 hours, I was ready with a WebSocket code at client-side and an async consumer in the backend. However, as expected, new code means new error and somehow the WebSocket connection couldn’t remain connected for more than a second. I went to take a coffee break (2, actually), woke up my teammates and fixed up the connection bug by shifting to synchronous code (I know, ouch). It worked and I had an hour remaining to finish up the chat.</p><h3>Coding Phase (6 hours to go)</h3><p>Technically, I was 2 minutes late with a working chat, but meh. With almost all core features done, we moved on to using the ML API in the frontend, but faced the grave CORS error on localhost origin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*UhkWr7UKgKiFs3pO" /></figure><p>Okay, I believe I know CORS very well, but I definitely didn’t expect this error to pop up with all correct OPTIONS response headers and request headers. Finally, I indeed manage to solve it by first converting our JSON data to string in request.<br>Finally, with an extra bug in rendering chart of floating data solved, I moved on to deploying the site on AWS EC2 with less than 4 hours remaining. Created new AWS RDS, messed around with security group rules to make it accessible by EC2, installed Redis and all requirements on an EC2 instance, and managed to expose the web service on a free domain. And we still had time left! So we changed the name to AgriConnect and got this app a logo!</p><h3>Coding Phase (&lt;2 hours to go)</h3><p>With our minds tired from unrest and our stomach happy with some light breakfast, we set out on polishing up our app with much-needed bug fixes, UI improvements and adding some small cool features (which actually created new issues to solve — a vicious cycle). Shravan wrapped up the pitch, we finished our GitHub repo and our work submission in the form of <a href="https://github.com/codefest-iit-bhu/haxplore-submissions/issues/14">an issue</a>. With 3 minutes remaining from the deadline, we pushed our last commit as a bug fix and… all done!</p><h3>Judging Phase</h3><p>After the intense coding round, we rested for an hour before we had to prepare for project presentation. Shravan finished the PPT in 15 minutes and we discussed all the possible questions amongst ourselves. After our pitch, the judges grilled us on the tech stack, especially the AWS services used. They asked questions related to scalability, ease of interface for farmers, offline use etc.</p><h3>Verdict</h3><p>If you’re still with me, would you like to know something even more exciting than building a product from scratch in an awesome hackathon? Well, it’s winning the event for sure! And indeed we did win the first position <em>and</em> prize money of INR 35, 000. The selfies of the team with the prize were worth all the hard work we did and sleep we sacrificed. It was really an awesome experience!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*LPl4QtrDCs4MSabdscnOyg.gif" /></figure><p>I encourage everyone to never miss out on showcasing your passion as a member of Dev community and to participate in such events to show your swags (I mean your laptop stickers, of course! :D)</p><p><strong>Note: </strong>Do not forget to clap this story (preferably, more than once) if you like the content! This story is originally posted on <a href="https://shivanshs9.me/medium/codefest19-hacking-mvp-ca7dcf329208">my website</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca7dcf329208" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/codefest19-hacking-mvp-ca7dcf329208">Hacking away an MVP in 24 hours</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DRF-Problems: Finally a Django library which implements RFC 7807!]]></title>
            <link>https://medium.com/swlh/drf-problems-21f7bb4d4675?source=rss-e87333ba73ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/21f7bb4d4675</guid>
            <category><![CDATA[django-rest-framework]]></category>
            <category><![CDATA[ietf]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[best-practices]]></category>
            <dc:creator><![CDATA[Shivansh Saini]]></dc:creator>
            <pubDate>Fri, 07 Jun 2019 23:30:47 GMT</pubDate>
            <atom:updated>2019-06-10T13:42:38.030Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K9Z-b-LPo60LFSUkl-mrUg.png" /><figcaption>Matrix effect with Python code (Source: Original)</figcaption></figure><h3>TL;DR</h3><p>Frustrated with tons of problems in DRF? Sorry, but this library doesn’t claim to fix them, regardless of what the library’s name may imply. :D This library does one thing only — implements <a href="https://tools.ietf.org/html/rfc7807">RFC 7807</a> in our favourite Django REST Framework! Or, in layman terms, it introduces “Problem Details” in the HTTP APIs.</p><h3>Why do I care?</h3><p>Well, let’s suppose that you’re a star of API engineering and follow the best practices whenever building anything RESTful. Your serializers are neat, follows OpenAPI spec, incorporates proper versioning of endpoints and you know how to name your endpoints.</p><p>Things were great until you realized that you need to inform clients of different kind of errors in the same endpoint. Now you get stuck googling and going through many of <a href="https://stackoverflow.com/questions/3050518/what-http-status-response-code-should-i-use-if-the-request-is-missing-a-required/3050561">Stack Overflow answers</a> on what status code to use!</p><p>Questions, like “Should I use plain old 400? Or be more explicit and use 406 or 412? But their meanings are wrong in this context…”, pop up in your brain, but these aren’t adequately answered by Stack Overflow. And finally, you’ve hit a wall with these stupid HTTP status codes which just can’t solve your application issues (which actually makes sense, in hindsight :)) One solution you may think of is to just keep a long list of codes of all kinds of application issues, and use them in some Serializer. The grave issue with this is how these codes and their description be communicated to the API consumer. Now this will make your API difficult for any new client to use readily.</p><p>Spotify, Google, Facebook etc also have different such schemas to explain these ‘problems’. And so, the biggest drawback of REST is the lack of standards to detail the problem… until <a href="https://en.wikipedia.org/wiki/Internet_Engineering_Task_Force"><strong>IETF</strong></a> published yet another document.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/0*cxZnaB23L0HaJVVo" /><figcaption>Source: <a href="https://restful.io/making-my-first-api-using-python-flask-8d7d83e45e36">My first experience creating an API</a></figcaption></figure><h3>RFC 7807 To The Rescue</h3><p><a href="https://tools.ietf.org/html/rfc7807">RFC 7807</a> provides a standard format for returning problem details from HTTP APIs. Summary of the document:</p><blockquote>- The data model for problem details is a JSON <a href="https://tools.ietf.org/html/rfc7159">RFC7159</a> object; when formatted as a JSON document, it uses the “application/problem+json” media type.</blockquote><blockquote>- New problem type definitions MUST document:<br> i. a type URI (typically, with the “http” or “https” scheme),<br> ii. a title that appropriately describes it (think short), and<br> iii. the HTTP status code for it to be used with.</blockquote><h3>Sure, it’s great. But is this implementation easy to use?</h3><p>I faced this problem myself and have been looking for some solution. I stumbled upon the one for <a href="https://github.com/zalando/problem">Java</a> and its <a href="https://github.com/zalando/problem-spring-web">Spring library</a>. Since I couldn’t find any similar solution for python, I realized I’d have to do it myself. So, as I am the consumer of this library too, I made this library keeping the developers in mind and how we love flexible stuff. The library is available at <a href="https://github.com/shivanshs9/drf-problems/">Github</a>, for free (Duh! :P). It’s also indexed by <a href="https://pypi.org/project/drf-problems/">Python Package Index</a>.</p><p>It’s based around the concept of reducing your exceptions to a ‘problem detail’ model mentioned above to communicate the problem directly via the API. A view is also included in the library for the error documentation and stuff. These are well and good, but it truly stands out by extending the DRF permission concept to include exceptions in it. Moreover, it’s upto-date with the latest DRF and works well with composable permissions. Now, one would no longer be confused with which permission failing after using two permissions with OR! To sate the ‘be flexible’ desire of most developers, this library provides mixins, which works well with your existing classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/0*DeouEsZ9-pifZvvd" /></figure><h3>Nice. Anyone care to tell how to try it out?</h3><p>To use this library, first follow the steps you usually follow for any Django library.</p><ul><li>Install using pip. pip install drf-problems</li><li>Add ‘<strong>drf_problems</strong>’ to your INSTALLED_APPS setting in your project’s settings.py.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca16ae7e119d10bf010c25a3e7dd019d/href">https://medium.com/media/ca16ae7e119d10bf010c25a3e7dd019d/href</a></iframe><p>This library also requires replacing the DRF exception handler with its own implementation. In your settings.py, update:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58f0a1e5e7627ec1b6a43a16842eb86c/href">https://medium.com/media/58f0a1e5e7627ec1b6a43a16842eb86c/href</a></iframe><p>To use the problem description url, you need to update your urls.py to include the urlpatterns of this library too:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14b1cd6c371223ef3c5adb7d42e34d43/href">https://medium.com/media/14b1cd6c371223ef3c5adb7d42e34d43/href</a></iframe><p>With this much work, the library would work with the existing DRF exceptions and your custom ones. For the problem detail, it uses:</p><ul><li><strong>type</strong> — URI made from either code or default_code attribute of exception.</li><li><strong>title</strong> — either title or default_detail attribute of exception.</li><li><strong>description</strong> (used in error documentation) — uses description attribute of exception.</li></ul><p>To use the error documentation with custom exceptions, these need to be registered so that its code can be inferred. Here’s a way to register your exception with a decorator:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/485d518fd5d25717e6c776d33ef81250/href">https://medium.com/media/485d518fd5d25717e6c776d33ef81250/href</a></iframe><p>Now with this done and using the ‘invalid_version’ code for the error documentation endpoint, its description and status code can be obtained.</p><p>To use these kinds of exceptions with DRF permissions, you would first need to ensure that the corresponding view inherits from the provided drf_problems.mixins.AllowPermissionWithExceptionViewMixin mixin, like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfbe6548b8fc8203d34619b1b32f30f7/href">https://medium.com/media/dfbe6548b8fc8203d34619b1b32f30f7/href</a></iframe><p>In the example above, a working permission is used which this library provides. MinimumVersionRequiredPermission takes in minimum API version as initialisation argument and checks that the request version is more than or equal to this minimum version. If not, then drf_problems.exceptions.DeprecatedVersionUsedException is raised.</p><p>Finally, for the permissions, use either drf_problems.permissions.ProblemPermissionMixin mixin class with your existing permissions, or extend directly from drf_problems.permissions.BaseProblemPermission. The exception instance to raise is used from the exception attribute defined on the permission or created from the class in exception_class attribute defined on the permission.</p><p>Here’s a sample permissions class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b2c9f9f9bff3d65ba65c6c0bb56570b/href">https://medium.com/media/5b2c9f9f9bff3d65ba65c6c0bb56570b/href</a></iframe><h3>What if it blows up my application?</h3><p>While I’ve released V1.0.0, I cannot take guarantee of any bugs which may result in your application after including this library. Just open up an issue <a href="https://github.com/shivanshs9/drf-problems/issues/new">here</a>, and we can figure out what can be done to solve it.</p><p>I appreciate all contributions — whether raising an issue, giving ideas for enhancement, opening a pull request or just discussing another IETF document! :D</p><h3>Didn’t quite catch your name yet</h3><p>Well, sorry about introducing myself so late. I’m Shivansh Saini, an undergrad student of CSE in IIT (BHU), Varanasi. I’ve had some experience in developing and deploying web applications, whether it be on Dynos, App Engine, EC2 or Kubernetes architecture with Ingress. Besides the obvious backend development, I’ve done frontend projects like a PWA using Vue.JS and android apps. It’s my first time writing a technical blog, so I’d love to hear any criticisms you have for me on anything I can improve on or did well.</p><p>Signing off, <br><strong>TheFaker</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21f7bb4d4675" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/drf-problems-21f7bb4d4675">DRF-Problems: Finally a Django library which implements RFC 7807!</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>