<?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>DEV Community: Abubakar Sadiq Sirajo</title>
    <description>The latest articles on DEV Community by Abubakar Sadiq Sirajo (@serdyq).</description>
    <link>https://dev.to/serdyq</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%2F638689%2F1ddf48e4-ce23-46a3-9b2d-497129a7d701.jpg</url>
      <title>DEV Community: Abubakar Sadiq Sirajo</title>
      <link>https://dev.to/serdyq</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/serdyq"/>
    <language>en</language>
    <item>
      <title>How to abort API requests in JavaScript</title>
      <dc:creator>Abubakar Sadiq Sirajo</dc:creator>
      <pubDate>Mon, 30 May 2022 03:29:12 +0000</pubDate>
      <link>https://dev.to/serdyq/how-to-abort-api-requests-in-javascript-k53</link>
      <guid>https://dev.to/serdyq/how-to-abort-api-requests-in-javascript-k53</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4dsQ4kbi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f5edkbyfzu4mbh85a30z.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4dsQ4kbi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f5edkbyfzu4mbh85a30z.jpg" alt="Let's get Started with Abort API requests" width="640" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Different reasons; to authenticate user credentials, fetch resources, create resources, and so much more.&lt;/p&gt;

&lt;p&gt;Did you know that you can abort an API request in JavaScript? By aborting, I mean canceling a request before it is completed (before you get a response or before the request gets to the server).&lt;/p&gt;

&lt;p&gt;There are many reasons why you may want to do this. One of them is to prevent a request from being sent to the server if the user has already navigated away from the page the request was made.&lt;/p&gt;

&lt;p&gt;Canceling requests can help you avoid unnecessary network traffic, save memory usage and resources, and improve performance.&lt;/p&gt;

&lt;p&gt;There are many ways to make API requests in JavaScript. In this article, I'll focus on &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/fetch"&gt;fetch&lt;/a&gt; and &lt;a href="https://axios-http.com/"&gt;axios&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So how do you do abort requests in these methods?&lt;/p&gt;

&lt;h2&gt;
  
  
  The AbortController Interface
&lt;/h2&gt;

&lt;p&gt;The Web API exposes the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/AbortController"&gt;AbortController&lt;/a&gt; interface, a JavaScript object that allows you to abort requests whenever you want. Here is how to create an &lt;code&gt;AbortController&lt;/code&gt; object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const controller = new AbortController()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This &lt;code&gt;controller&lt;/code&gt; object has two important properties for aborting requests.&lt;/p&gt;

&lt;p&gt;The first property is the &lt;code&gt;signal&lt;/code&gt; object. This object is a unique identifier for the request. The structure of this object is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  // other properties
  aborted: false,
  onabort: null
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second property is a method called &lt;code&gt;abort()&lt;/code&gt;. This method is used to update the &lt;code&gt;aborted&lt;/code&gt; flag of the unique request signal. When this method is called, all observers of the &lt;code&gt;signals&lt;/code&gt; object will be notified, and the requests will be canceled.&lt;/p&gt;

&lt;p&gt;When the &lt;code&gt;abortRequest&lt;/code&gt; function is called at any point in your application (such as a button click event, for example), the &lt;code&gt;abort&lt;/code&gt; method is called, the &lt;code&gt;abortSignal&lt;/code&gt; object will be updated, and all observers will be notified.&lt;/p&gt;

&lt;p&gt;Now let's see how to use this in &lt;code&gt;fetch&lt;/code&gt; and &lt;code&gt;axios&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Aborting API Requests in Fetch
&lt;/h2&gt;

&lt;p&gt;The fetch method is a JavaScript function used to make API requests. It takes two arguments: the URL of the API endpoint and an object containing the request options:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch(api, requestOptions)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;requestOptions&lt;/code&gt; object accept a many properties, but the most important is the &lt;code&gt;signal&lt;/code&gt; property. You can then attach the &lt;code&gt;signal&lt;/code&gt; object from the controller to this property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const controller = new AbortController()

const abortSignal = controller.signal

function abortRequest() {
  controller.abort()
}

fetch("api", {
  signal: abortSignal,
})

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this, when the &lt;code&gt;abortRequest&lt;/code&gt; function is called, the &lt;code&gt;fetch&lt;/code&gt; expression will be notified, and the request will be canceled.&lt;/p&gt;

&lt;h2&gt;
  
  
  Aborting API Requests in Axios
&lt;/h2&gt;

&lt;p&gt;Axios is a JavaScript library that is used to make API requests. It has a very similar syntax to the &lt;code&gt;fetch&lt;/code&gt; method. It also accepts a &lt;code&gt;signal&lt;/code&gt; property in the request options object. So we can also attach the &lt;code&gt;signal&lt;/code&gt; object from the controller like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const controller = new AbortController()

const abortSignal = controller.signal

function abortRequest() {
  controller.abort()
}

axios.get("api", {
  signal: abortSignal,
})

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the &lt;code&gt;aborted&lt;/code&gt; flag of the &lt;code&gt;signal&lt;/code&gt; object is updated to &lt;code&gt;true&lt;/code&gt;, this &lt;code&gt;axios&lt;/code&gt; expression will be notified, and the request will be canceled.&lt;/p&gt;

&lt;p&gt;Even for new methods of making API requests, by accepting a &lt;code&gt;signal&lt;/code&gt; property in their request options object, you can abort requests using the &lt;code&gt;abort()&lt;/code&gt; method.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>api</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What was your first language as a Software developer</title>
      <dc:creator>Abubakar Sadiq Sirajo</dc:creator>
      <pubDate>Sun, 17 Apr 2022 17:23:40 +0000</pubDate>
      <link>https://dev.to/serdyq/what-was-your-first-language-as-a-software-developer-217d</link>
      <guid>https://dev.to/serdyq/what-was-your-first-language-as-a-software-developer-217d</guid>
      <description></description>
      <category>discuss</category>
      <category>career</category>
      <category>news</category>
      <category>motivation</category>
    </item>
    <item>
      <title>UPDATE &gt; MariaDB</title>
      <dc:creator>Abubakar Sadiq Sirajo</dc:creator>
      <pubDate>Sun, 17 Apr 2022 17:19:12 +0000</pubDate>
      <link>https://dev.to/serdyq/update-mariadb-1685</link>
      <guid>https://dev.to/serdyq/update-mariadb-1685</guid>
      <description>&lt;p&gt;The UPDATE command helps us to change or modify the records that have already been inserted into a table. You can combine it with the WHERE clause to specify the record that is to be updated. Here is the syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UPDATE tableName SET field=newValue, field2=newValue2,...  
[WHERE ...]  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The UPDATE command can also be combined with clauses such as SET, WHERE, LIMIT, and ORDER BY. You will see this shortly:&lt;/p&gt;

&lt;p&gt;Let’s change the price of the book with an id of 1 from 200 to 250:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UPDATE price 
SET price = 250
WHERE id = 1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>database</category>
      <category>mariadb</category>
      <category>sql</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Python string | swapcase()</title>
      <dc:creator>Abubakar Sadiq Sirajo</dc:creator>
      <pubDate>Fri, 15 Apr 2022 10:34:23 +0000</pubDate>
      <link>https://dev.to/serdyq/python-string-swapcase-35lc</link>
      <guid>https://dev.to/serdyq/python-string-swapcase-35lc</guid>
      <description>&lt;p&gt;The string swapcase() method converts all uppercase characters to lowercase and vice versa of the given string and return it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;string_name.swapcase()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here &lt;em&gt;string_name&lt;/em&gt; is the string whose case are to be swapped.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Parameter:&lt;/strong&gt;The swapcase() method does not take any parameter&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Return value:&lt;/strong&gt;&lt;br&gt;
The swapcase() method returns a string with all the case changed.&lt;/p&gt;

&lt;p&gt;Below is the python implementation of the swapcase() method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Python program to demonstrate the use of
# Swapcase() method

string = "wORldGREAtestday"

# Print after swapping all case 
print(string.swapcase())

string = "python"
print(string.swapcase())

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WorLDgreaTESTDAY
PYTHON
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>dulah</category>
    </item>
  </channel>
</rss>
