<?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: Metete Welete</title>
    <description>The latest articles on DEV Community by Metete Welete (@metete_welete).</description>
    <link>https://dev.to/metete_welete</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%2F674447%2F07422e66-c3de-49dd-9718-fbfd0385a5d9.jpg</url>
      <title>DEV Community: Metete Welete</title>
      <link>https://dev.to/metete_welete</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/metete_welete"/>
    <language>en</language>
    <item>
      <title>Introduction to micro-services and how they can be used to build scalable and flexible systems</title>
      <dc:creator>Metete Welete</dc:creator>
      <pubDate>Thu, 29 Dec 2022 19:38:48 +0000</pubDate>
      <link>https://dev.to/metete_welete/introduction-to-micro-services-and-how-they-can-be-used-to-build-scalable-and-flexible-systems-4j2f</link>
      <guid>https://dev.to/metete_welete/introduction-to-micro-services-and-how-they-can-be-used-to-build-scalable-and-flexible-systems-4j2f</guid>
      <description>&lt;p&gt;Microservices are an increasingly popular way to build modern, scalable, and flexible applications. With microservices, an application is structured as a collection of small, independent services that communicate with each other using well-defined APIs.&lt;/p&gt;

&lt;p&gt;This modular approach allows teams to develop, test, and deploy services independently, making it easier to iterate and easier to iterate and release new features. It also allows for more efficient resource utilization, as you can scale individual services as needed rather than the entire application.&lt;/p&gt;

&lt;p&gt;In this article, we’ll take a closer look at microservices and how they can help you build scalable and flexible systems.&lt;/p&gt;

&lt;p&gt;Before we get into Microservices and what they really are, let’s take an insight on monolithic architecture and what it is.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Monolithic Architecture&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Monolithic architecture is a server-side system based on single applications. At the initial stage, this architecture makes building and deploying an application quick but poses a lot of challenges along the line.&lt;/p&gt;

&lt;p&gt;Some challenges with the monolithic architecture are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Traditionally, monolith applications have a lot of shared libraries, so they’re highly dependent on each other. If you change a library, you need to understand that you could effectively take the entire application down.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Another challenge is that we are constrained to a particular framework and/or language that was initially used in building the application.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Microservice Architecture&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Microservices is a software architecture style that structures an application as a collection of small, independent services that communicate with each other using well-defined APIs. These services are designed to be easy to develop, test, and maintain, and they can be deployed and scaled independently.&lt;/p&gt;

&lt;p&gt;One of the main benefits of microservices is that they can make it easier to build scalable and flexible systems. Because each service is self-contained and communicates with other services through APIs, you can easily add or remove services as needed without affecting the rest of the system. &lt;/p&gt;

&lt;p&gt;This modular approach can also make it easier to identify and fix issues within the system, as you can focus on a single service rather than trying to debug a monolithic codebase.&lt;/p&gt;

&lt;p&gt;There are several other benefits to using microservices, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Increased agility: Microservices allow you to make changes to a specific part of the system without affecting the entire application. This can be particularly useful for organizations that need to quickly iterate and release new features.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Improved reliability: Because each service is independently deployable and scalable, you can more easily ensure that the system as a whole is highly available. If one service goes down, the rest of the system can continue to function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Better use of resources: Microservices can allow you to optimize resource utilization by only scaling the services that need it. This can help you save money on infrastructure costs.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To use microservices, you’ll need to design your application as a collection of independent services that communicate with each other using APIs. You’ll also need to choose a technology stack that supports the development of microservices such as containers and a container orchestration platform like kubernates.&lt;/p&gt;

&lt;p&gt;I hope this gives you a good overview of microservices and how they can be used to build scalable and flexible systems. &lt;/p&gt;

&lt;p&gt;Follow me on twitter &lt;a href="//www.twitter.com/w_lete"&gt;@w_lete&lt;/a&gt; and let me know if you have any questions!&lt;/p&gt;

</description>
      <category>tooling</category>
    </item>
    <item>
      <title>Sort Characters By Frequency - Leetcode</title>
      <dc:creator>Metete Welete</dc:creator>
      <pubDate>Sun, 25 Sep 2022 21:46:30 +0000</pubDate>
      <link>https://dev.to/metete_welete/sort-characters-by-frequency-leetcode-5aal</link>
      <guid>https://dev.to/metete_welete/sort-characters-by-frequency-leetcode-5aal</guid>
      <description>&lt;p&gt;&lt;a href="https://leetcode.com/problems/sort-characters-by-frequency/"&gt;Sort Characters By Frequency&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While this is a problem with difficulty at medium, I actually enjoyed solving it and had it run on first write of code.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I first had to break it down by making a string that holds all the value as unique values and also created a map of the values and the number of times they appeared in the given string.&lt;/p&gt;

&lt;p&gt;I then looped through the reverse of length of the strings and joined each value as they appeared in the map in a new string.&lt;/p&gt;

&lt;p&gt;This isn't the most optimal solution as it takes O(n^2) to run.&lt;/p&gt;

&lt;p&gt;I'll update this article when I get a more optimal solution.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Print In Order - Leetcode</title>
      <dc:creator>Metete Welete</dc:creator>
      <pubDate>Sat, 24 Sep 2022 20:29:50 +0000</pubDate>
      <link>https://dev.to/metete_welete/print-in-order-leetcode-1i6c</link>
      <guid>https://dev.to/metete_welete/print-in-order-leetcode-1i6c</guid>
      <description>&lt;p&gt;&lt;a href="https://leetcode.com/problems/print-in-order/submissions/"&gt;Print-In-Order&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This problem was quite tricky because I had to read it up to 3 times to understand what was required from us for the task.&lt;/p&gt;

&lt;p&gt;First, I created an array of the boolean states of the threads, or print order.&lt;/p&gt;

&lt;p&gt;The first thread is meant to run before the order two so I left it as is to run and change the boolean state in the initialized array above.&lt;/p&gt;

&lt;p&gt;The second thread, I used a while loop to check if the first thread has been run. Do this by checking the boolean state of the first thread in the array. If yes, you can print the second thread and change the boolean state in the array.&lt;/p&gt;

&lt;p&gt;The third thread is just like the second thread but now, we use the while loop check the state of the second thread instead of the first thread.&lt;/p&gt;

&lt;p&gt;Following this steps, the solution can be implemented in any object oriented programming language.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Palindrome Number - Leetcode</title>
      <dc:creator>Metete Welete</dc:creator>
      <pubDate>Fri, 23 Sep 2022 18:03:48 +0000</pubDate>
      <link>https://dev.to/metete_welete/palindrome-number-leetcode-4kk9</link>
      <guid>https://dev.to/metete_welete/palindrome-number-leetcode-4kk9</guid>
      <description>&lt;p&gt;&lt;a href="https://leetcode.com/problems/palindrome-number/"&gt;Palindrome Number&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Given an integer x, return true if x is palindrome integer.&lt;/p&gt;




&lt;p&gt;Solving this could be as easy as converting the integer to a string and checking if the string is equal to it's reverse.&lt;/p&gt;




&lt;p&gt;But there is a statement at the bottom of the question&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Follow up: Could you solve it without converting the integer to a string?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is the approach I used as to task my mind a bit.&lt;/p&gt;

&lt;p&gt;So first I checked for possible matches in additions and subtractions but it wasn't providing useful output.&lt;/p&gt;

&lt;p&gt;I tried converting to binary to see if I could see patterns but I didn't find any.&lt;/p&gt;

&lt;p&gt;Then I used the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create an empty array which I would use later to store the reverse integers&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a loop that would run if the integer was greater than 0&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Divide the integer by 10&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Store the remainder in the array and have the new integer run through the loop until it gets to 0.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check if the array is equal to its reverse to return True or False.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This approach stores the remainder of the integer after being divided by 10 which forms the reverse of the integer in the array.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Remove Given Element from an Array - Leetcode</title>
      <dc:creator>Metete Welete</dc:creator>
      <pubDate>Thu, 22 Sep 2022 06:35:50 +0000</pubDate>
      <link>https://dev.to/metete_welete/remove-given-element-from-an-array-leetcode-12k1</link>
      <guid>https://dev.to/metete_welete/remove-given-element-from-an-array-leetcode-12k1</guid>
      <description>&lt;p&gt;&lt;a href="https://leetcode.com/problems/remove-element/"&gt;Leetcode - Remove Element&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The question says: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The relative order of the elements may be changed.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You'll also not want to create another array as the expected Space complexity is O(1).&lt;/p&gt;

&lt;p&gt;Here's how I tackled it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Store the length of the given array in a variable, nums_length&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Declare a variable length_of_nums to 0. This would later act as the counter in our loop&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a loop to run if length_of_nums is less than nums_length&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a second loop to check if the length_of_nums(counter) element in the nums array is equal to the value given to check. if the condition for the loop is not met, increment the length_of_nums by 1&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the two elements are same, pop out the element in the array&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;decrement the nums_length by 1&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check if the nums_length is equal to the length_of_nums to break out of the inner loop. (This checks for edge cases)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;return length_of_nums&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using this approach gives you the array in memory without duplicates so you can return the new length of the array.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Remove duplicates from sorted array</title>
      <dc:creator>Metete Welete</dc:creator>
      <pubDate>Wed, 21 Sep 2022 01:24:50 +0000</pubDate>
      <link>https://dev.to/metete_welete/remove-duplicates-from-sorted-array-289j</link>
      <guid>https://dev.to/metete_welete/remove-duplicates-from-sorted-array-289j</guid>
      <description>&lt;p&gt;&lt;a href="https://leetcode.com/problems/remove-duplicates-from-sorted-array/"&gt;Remove Duplicates From Sorted Array Leetcode&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So in order to remove the duplicates from the sorted array without creating a new array, I had to traverse through the given array and delete any next element that equals the current element&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;create an incrementing value i and set it to 1&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Traverse through the nums array&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;check for edge cases to avoid going over the range of the array's index&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;loop through the next ith elements to check if they are equal to the current element&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;remove any ith element that is equal to the current element &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the ith element is not equal to the current element, increment i &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;break out of the loop if edge cases are met i.e if i is greater than or equal to the length of the nums array&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Using this approach gives you the array in memory without duplicates so you can return the length.&lt;/p&gt;

&lt;p&gt;You can view my code in python through &lt;a href="https://github.com/nodebe/dsa_challenges/blob/main/easy_remove_duplicates.py"&gt;Remove Duplicates From Sorted Array&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>PAGINATION USING PYTHON, REST API, FLASK &amp; MONGODB</title>
      <dc:creator>Metete Welete</dc:creator>
      <pubDate>Wed, 19 Jan 2022 21:17:53 +0000</pubDate>
      <link>https://dev.to/metete_welete/pagination-using-python-rest-api-flask-mongodb-2gop</link>
      <guid>https://dev.to/metete_welete/pagination-using-python-rest-api-flask-mongodb-2gop</guid>
      <description>&lt;p&gt;I was recently involved in a project that required me to implement pagination from the backend and I would like to share the easy way I did it through this post.&lt;br&gt;
Now just like I initially did, you might have checked online for a python-mongo module that could help achieve this but I assure you that this article would be easier and more light-weight.&lt;/p&gt;

&lt;p&gt;For this post, I will be using a simple books API that returns a passed in number of books requested from the database. We will be able to pass in the page number and amount(limit) of books to be returned. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Please note that this article was written with Windows users in mind. If you are on another OS, you could check out the commands to perform similar tasks online.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;File Structure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, let me describe how my file structure is:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdub7wh1in5d4oz5yqc1x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdub7wh1in5d4oz5yqc1x.png" alt="file structure of api"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have a venv (virtual environment) folder where all modules required for this project are installed. You can quickly do that by following these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open your terminal (command prompt) in the books_api folder,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you don’t already have the virtual environment package installed on your pc, you should follow step 3, else you can skip to step 4,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run &lt;code&gt;pip install virtualenv&lt;/code&gt;. This should install packages required for creating a virtual environment,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run &lt;code&gt;virtualenv venv&lt;/code&gt;, where &lt;code&gt;venv&lt;/code&gt; is the name of the virtual environment. This can be named anything, but we like to keep it simple,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run &lt;code&gt;venv\scripts\activate&lt;/code&gt; to activate the virtual environment in the books_api folder.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Installations&lt;/strong&gt;&lt;br&gt;
Just before we kick off, if you don’t already have these modules, then you can quickly install them using &lt;code&gt;pip install&lt;/code&gt; in your already activated virtual environment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;flask flask-restful pymongo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Setting up our Resources&lt;/strong&gt;&lt;br&gt;
I am going to be setting up Resource for flask-restful in the __init__.py file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;__init__.py&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pymongo&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;MongoClient&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask_restful&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Api&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;api&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Api&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Connecting to local host 
&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MongoClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;mongodb://localhost:27017/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Get the books_db and store in db
&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;books_db&lt;/span&gt;

&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;.books&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Books&lt;/span&gt;

&lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_resource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Books&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;books&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;books.py&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask_restful&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Resource&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reqparse&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;.&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;bson&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json_util&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;

&lt;span class="n"&gt;books_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reqparse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RequestParser&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;books_data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;help&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="n"&gt;Page&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;books_data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;limit&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;help&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="n"&gt;Limit&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Books&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Resource&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;'''&lt;/span&gt;&lt;span class="s"&gt;
        Methods related to the Books endpoint are written 
        here.

    GET:
       Input: {&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;page&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;:Int, &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;limit&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;:Int}
       Output: {&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;total_number&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;:Int, &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;page&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;:Int, 
       &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;showing&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;:Int, books:List}
    &lt;/span&gt;&lt;span class="sh"&gt;'''&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;books_data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse_args&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

        &lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;page&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;page_limit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;limit&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

        &lt;span class="c1"&gt;# Total number of books
&lt;/span&gt;        &lt;span class="n"&gt;books_count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;books&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;count_documents&lt;/span&gt;&lt;span class="p"&gt;({})&lt;/span&gt;

        &lt;span class="c1"&gt;# Fetching books data and paginating
&lt;/span&gt;        &lt;span class="n"&gt;fetch_books&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;books&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;_id&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;skip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page_limit&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page_limit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="n"&gt;books_fetched&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json_util&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fetch_books&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;

        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;total_number&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;books_count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;page&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;showing&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;page_limit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;books&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;books_fetched&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;app.py&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;books_api&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;__main__&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To run this application, open the activated venv in your terminal and run &lt;code&gt;python app.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
This post has been made very basic for easy understanding and implementation. You don’t really need to have this exact project. You just need to understand the concept and you’re good to go. All the code has been uploaded to GitHub, you can view it here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/nodebe/books_api" rel="noopener noreferrer"&gt;Books_Api&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope I was able to help you through this post. I am open to answering questions in the comment section below.&lt;/p&gt;

&lt;p&gt;Stay coded! :)&lt;/p&gt;

</description>
      <category>python</category>
      <category>flask</category>
      <category>mongodb</category>
      <category>api</category>
    </item>
  </channel>
</rss>
