<?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: rajshirolkar</title>
    <description>The latest articles on Forem by rajshirolkar (@rajshirolkar).</description>
    <link>https://forem.com/rajshirolkar</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%2F499603%2Fe1bfafc5-208f-4570-8938-9e08947d1466.jpeg</url>
      <title>Forem: rajshirolkar</title>
      <link>https://forem.com/rajshirolkar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rajshirolkar"/>
    <language>en</language>
    <item>
      <title>FastAPI - moving on from Flask</title>
      <dc:creator>rajshirolkar</dc:creator>
      <pubDate>Sat, 31 Dec 2022 09:43:11 +0000</pubDate>
      <link>https://forem.com/rajshirolkar/fastapi-moving-on-from-flask-3jg7</link>
      <guid>https://forem.com/rajshirolkar/fastapi-moving-on-from-flask-3jg7</guid>
      <description>&lt;p&gt;If you're a Python developer, you've probably heard of Flask, the micro web framework that has gained a lot of popularity in recent years. However, if you're looking to build a high-performance web application, you may want to consider FastAPI as an alternative.&lt;/p&gt;

&lt;p&gt;One of the major drawbacks of Flask is that it is not built for concurrency. In Python, implementing multithreading can be very complicated, as the language itself has some limitations. This means that if you want to build a web application that can handle a high volume of requests, Flask may not be the best choice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Async support
&lt;/h2&gt;

&lt;p&gt;One of the major limitations of Flask is its lack of async support. In Python, multithreading is very complicated, and the &lt;code&gt;global interpreter lock (GIL)&lt;/code&gt; makes it difficult to achieve true parallelism. This is where async programming comes in. Async allows you to write code that can perform IO-bound and high-level structured network code in an async manner.&lt;/p&gt;

&lt;p&gt;FastAPI, on the other hand, fully supports async. It's built on top of Starlette, which is an async-compatible web framework, and uses the new async/await syntax introduced in Python 3.5. This means you can write async code in FastAPI just like you would in any other async framework, such as &lt;code&gt;aiohttp&lt;/code&gt; or Sanic.&lt;/p&gt;

&lt;p&gt;Here's an example of a simple async endpoint in FastAPI:&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="nn"&gt;fastapi&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;FastAPI&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;FastAPI&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;read_root&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"World"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compare this to the equivalent in Flask:&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="nn"&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="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&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="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Hello, World!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Performance
&lt;/h2&gt;

&lt;p&gt;FastAPI is also faster than Flask. It uses the &lt;code&gt;uvicorn&lt;/code&gt; server, which is built on top of the &lt;code&gt;asyncio&lt;/code&gt; library and the &lt;code&gt;uvloop()&lt;/code&gt; event loop. &lt;code&gt;uvloop()&lt;/code&gt; is a fast implementation of the &lt;code&gt;asyncio&lt;/code&gt; event loop, written in Cython and based on &lt;code&gt;libuv&lt;/code&gt;, the same library that powers Node.js. This means that FastAPI can handle a lot more requests per second compared to Flask.&lt;/p&gt;

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

&lt;p&gt;In fact, a benchmark by the FastAPI team showed that FastAPI is up to 3x faster than Flask in some cases. Here's a comparison of the two frameworks using the wrk tool:&lt;/p&gt;

&lt;p&gt;For Flask -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Flask &lt;span class="o"&gt;(&lt;/span&gt;Python 3.7, uWSGI 2.0.18.1&lt;span class="o"&gt;)&lt;/span&gt;:
Running 30s &lt;span class="nb"&gt;test&lt;/span&gt; @ http://127.0.0.1:5000/
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    28.41ms   20.74ms 635.86ms   80.54%
    Req/Sec     2.00k   439.36     3.44k    80.91%
  240973 requests &lt;span class="k"&gt;in &lt;/span&gt;30.09s, 41.97MB &lt;span class="nb"&gt;read
  &lt;/span&gt;Socket errors: connect 0, &lt;span class="nb"&gt;read &lt;/span&gt;240973, write 0, &lt;span class="nb"&gt;timeout &lt;/span&gt;0
  Non-2xx or 3xx responses: 240973
Requests/sec:   7975.34
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For FastAPI -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;FastAPI &lt;span class="o"&gt;(&lt;/span&gt;Python 3.7, uvicorn 0.11.2&lt;span class="o"&gt;)&lt;/span&gt;:
Running 30s &lt;span class="nb"&gt;test&lt;/span&gt; @ http://127.0.0.1:8000/
  12 threads and 400 connections
  Thread Stats Avg Stdev Max +/- Stdev
    Latency 5.12ms 3.29ms 37.45ms 85.08%
    Req/Sec 6.70k 1.37k 10.22k 65.39%
  802934 requests &lt;span class="k"&gt;in &lt;/span&gt;30.10s, 134.69MB &lt;span class="nb"&gt;read
  &lt;/span&gt;Socket errors: connect 0, &lt;span class="nb"&gt;read &lt;/span&gt;802934, write 0, &lt;span class="nb"&gt;timeout &lt;/span&gt;0
  Non-2xx or 3xx responses: 802934
Requests/sec: 26702.16
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, FastAPI is able to handle almost 3x the number of requests per second compared to Flask. This makes it a great choice for building high-performance APIs.&lt;/p&gt;

&lt;p&gt;Flask&lt;/p&gt;

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

&lt;p&gt;FastAPI&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Data validation and parsing
&lt;/h2&gt;

&lt;p&gt;FastAPI also has built-in support for data validation and parsing using Pydantic. Pydantic is a library that allows you to define your API's request and response bodies using Python's built-in type hints. FastAPI will then automatically validate the request data and parse it into the correct types.&lt;/p&gt;

&lt;p&gt;Here's an example of a request body defined using Pydantic in FastAPI:&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="nn"&gt;pydantic&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;BaseModel&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BaseModel&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="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
    &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;
    &lt;span class="n"&gt;tax&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;FastAPI will automatically validate the request data and return any validation errors if the data is invalid. This saves you a lot of time and effort compared to manually validating the request data in Flask.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, if you're a Python developer looking to build APIs, you should consider using FastAPI instead of Flask. It's a modern, fast, and easy-to-use web framework that fully supports async programming and comes with built-in support for data validation and parsing. Give it a try and see how it can improve your API development workflow.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to use Async/Await in Unity</title>
      <dc:creator>rajshirolkar</dc:creator>
      <pubDate>Sat, 31 Dec 2022 09:28:23 +0000</pubDate>
      <link>https://forem.com/rajshirolkar/how-to-use-asyncawait-in-unity-6nn</link>
      <guid>https://forem.com/rajshirolkar/how-to-use-asyncawait-in-unity-6nn</guid>
      <description>&lt;p&gt;Async/Await is one of the most useful features in any programming language. In single threaded applications or applications like Unity where the UI runs on a single thread it is extremely useful for smooth functioning of the app to make Async calls which won’t block the main UI thread . We’ll get the whole code first so people who are frantically trying to solve the issues in their project can have a quick peek.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using UnityEngine;  
using System.Threading.Tasks;public class TaskExample : MonoBehaviour  
{  
    float \_elapsed = 0;  
    void Start()  
    {  
        Debug.Log("Start begins"); //Initialize a task completion source.  
        //This will be our source for creating a task and also holding the result on it's completion.  

var tcs = new TaskCompletionSource&amp;lt;Vector3&amp;gt;();  
        Task.Run(async () =&amp;gt;  
        {  
            Debug.Log("Task started");  
            tcs.SetResult(await LongRunningTask());  
            Debug.Log("Task stopped");  
        });// ConfigureAwait must be true to get unity main thread context  
        tcs.Task.ConfigureAwait(true).GetAwaiter().OnCompleted(() =&amp;gt;  
        {  
            Debug.Log("Task completed");  
            transform.Rotate(tcs.Task.Result);  
        });Debug.Log("Start method ends");  
    }void Update()  
    {  
        if (\_elapsed &amp;gt; 1)  
        {  
            Debug.Log($"Update loop running for : " + Time.realtimeSinceStartup + " seconds");  
            \_elapsed = 0;  
        }  
        \_elapsed += Time.deltaTime;  
    }async Task&amp;lt;Vector3&amp;gt; LongRunningTask()  
    {  
        var rand = new System.Random();  
        var v = Vector3.zero;  
        // Do somethings that takes a long time  
        for (var i = 0; i &amp;lt; 30000000; i++)  
        {  
            v = new Vector3(rand.Next(0, 360), rand.Next(0, 360), rand.Next(0, 360));  
        }  
        return v;  
    }  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Log :&lt;/p&gt;

&lt;p&gt;The logs depict the flow of the code as it excutes the async tasks.&lt;/p&gt;

&lt;p&gt;Async/await in C# is similar to promises in javascript to some extent. The underlying concept is the same.&lt;/p&gt;

&lt;p&gt;You create a task and send it to say fetch some data from the server. Next you set a means for our code to store the result of the task whenever it comes back with a response from the server.&lt;/p&gt;

&lt;p&gt;In the above example we create a TaskCompletionSource which will provide us with a source to create the task and also a source to hold the result on the completion of the task.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var tcs = new TaskCompletionSource&amp;lt;Vector3&amp;gt;();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create the Task :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Task.Run(async () =&amp;gt;  
        {  
            Debug.Log("Task started");  
            tcs.SetResult(await LongRunningTask());  
            Debug.Log("Task stopped");  
        });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the result of the task on completion&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// ConfigureAwait must be true to get unity main thread context  
        tcs.Task.ConfigureAwait(true).GetAwaiter().OnCompleted(() =&amp;gt;  
        {  
            Debug.Log("Task completed");  
            transform.Rotate(tcs.Task.Result);  
        });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the LongRunningTask( ) method returns a Vector3 which dictates the rotation for our gameobject to which this script is attached. The result of the LongRunningTask( ) method can be accessed by the Task.Result property which we set in&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tcs.SetResult(await LongRunningTask());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need to create a function called LongRunningTask() which will be async and will return a Vector3 which dictates the rotation for our gameobject to which this script is attached.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async Task&amp;lt;Vector3&amp;gt; LongRunningTask()  
    {  
        var rand = new System.Random();  
        var v = Vector3.zero;  
        // Do somethings that takes a long time  
        for (var i = 0; i &amp;lt; 30000000; i++)  
        {  
            v = new Vector3(rand.Next(0, 360), rand.Next(0, 360), rand.Next(0, 360));  
        }  
        return v;  
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note : the return type is enclosed in Task&amp;lt;&amp;gt;. I made this mistake and spent a good 5 minutes wondering why I was getting an error.&lt;/p&gt;

&lt;p&gt;Now in Unity Editor lets create a new scene and add a 3D Object of a capsule.&lt;/p&gt;

&lt;p&gt;Create a capsule so we can see it rotate.&lt;/p&gt;

&lt;p&gt;Now attach our script to this capsule and run! We can see the flow of the code in the logs and we can also see the capsule rotating in the scene.&lt;/p&gt;

</description>
      <category>unity3d</category>
      <category>csharp</category>
      <category>programming</category>
    </item>
    <item>
      <title>FastAPI over HTTPS for development on Windows</title>
      <dc:creator>rajshirolkar</dc:creator>
      <pubDate>Sat, 03 Apr 2021 14:23:01 +0000</pubDate>
      <link>https://forem.com/rajshirolkar/fastapi-over-https-for-development-on-windows-2p7d</link>
      <guid>https://forem.com/rajshirolkar/fastapi-over-https-for-development-on-windows-2p7d</guid>
      <description>&lt;p&gt;Today we'll implement FastAPI over HTTPS using mkcert and setup our own Certificate Authority(CA) on our localhost. &lt;/p&gt;

&lt;p&gt;Note: since this is a self-signed certificate you might get a warning before accessing your API depending on which browser you're using.&lt;/p&gt;

&lt;p&gt;We'll get started with the code right away so if your boss has told you "Cool get this running over https by EOD" you are in the right place.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open cmd and make a directory for our app.
```
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;-&amp;gt; mkdir fastapi-https&lt;br&gt;
-&amp;gt; cd fastapi-https&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
+ Create and activate a virtual environment for your project and install fastapi and uvicorn in our virtual environment.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-&amp;gt; python -m venv ./venv&lt;br&gt;
-&amp;gt; .\venv\Scripts\activate&lt;br&gt;
(venv) -&amp;gt; pip install fastapi uvicorn &lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;It's always a good practice to create [virtual environments](https://realpython.com/python-virtual-environments-a-primer/) 

+ Open the _fastapi-https_ folder in VSCode and create a directory _app_ which will contain our FastAPI application in *app/main.py*. Also create a file *server.py* to run our [Uvicorn](https://www.uvicorn.org/) server and use it to serve our FastAPI app.
So your directory structure should look like this:
    ![Alt Directory Structure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qgnuj7wrrgsvs9u3ewck.PNG)

+ Paste the following code in *app/main.py* which will create a FastAPI route for us.
```python


    from fastapi import FastAPI

    app = FastAPI()

    @app.get('/')
    def read_main():
        return { "message" : "Hello World of FastAPI HTTPS"}


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

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;Since FastAPI doesn't come with a built-in web server like Flask and Django, we will be using Uvicorn which is an ASGI server. In the file &lt;em&gt;server.py&lt;/em&gt; paste the following code -
```python
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;import uvicorn&lt;/p&gt;

&lt;p&gt;if &lt;strong&gt;name&lt;/strong&gt; == '&lt;strong&gt;main&lt;/strong&gt;':&lt;br&gt;
    uvicorn.run("app.main:app",&lt;br&gt;
                host="0.0.0.0",&lt;br&gt;
                port=8432,&lt;br&gt;
                reload=True,&lt;br&gt;
                )&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
In this code in the main function we essentially tell the uvicorn server "Dude! Go to app.main and run whatever this 'app' is" and then we mention the host and port and yeah we do want to reload and all those things.

+ Now its run the server.py file with `python server.py` and go to this link http://localhost:8432/
    ![Alt It worked!](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w74pzvouv5fjau3y3m8q.PNG)

+ It works! But over "http" 🙄 this won't do in production. We need HTTPS in production. If you want to learn more about how HTTPS works, I will be writing another article here.
To get HTTPS we need to install [mkcert](https://github.com/FiloSottile/mkcert). Mkcert is a free way to get a self signed certificate for your app so it can run over HTTPS.
Install mkcert using [Chocolatey](https://chocolatey.org/install)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-&amp;gt; choco install mkcert&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
+ You need to generate the certificate and add to your CA with the mkcert utility
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-&amp;gt; mkcert -install&lt;br&gt;
-&amp;gt; mkcert localhost 127.0.0.1 ::1&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
+ The certificate is at "localhost+2.pem" and the key at "localhost+2-key.pem" in our project folder. I like to rename the files as "cert.pem" and "key.pem" so its a bit easier on the eyes.

+ Now we just need to tell Uvicorn the location of these files and Uvicorn will do all the HTTPS heavy-lifting for us. In *server.py* add the ssl arguemnts
```python


import uvicorn

if __name__ == '__main__':
    uvicorn.run("app.main:app",
                host="0.0.0.0",
                port=8432,
                reload=True,
                ssl_keyfile="./key.pem", 
                ssl_certfile="./cert.pem"
                )


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

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;Voila! Go to &lt;a href="https://localhost:8432/docs" rel="noopener noreferrer"&gt;https://localhost:8432/docs&lt;/a&gt; and we now have the sweet green text
&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%2Fatzp9y7fbhf8tp00dpyt.png" alt="Alt Connection Secure!"&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>fastapi</category>
      <category>https</category>
      <category>windows</category>
    </item>
  </channel>
</rss>
