<?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: Lucas S Nogueira</title>
    <description>The latest articles on Forem by Lucas S Nogueira (@snlucas).</description>
    <link>https://forem.com/snlucas</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%2F638934%2Ff53fd472-c49f-4ce9-8bc7-3e1636a9548f.png</url>
      <title>Forem: Lucas S Nogueira</title>
      <link>https://forem.com/snlucas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/snlucas"/>
    <language>en</language>
    <item>
      <title>Minha Experiência Frustrada Com Github Actions E AWS</title>
      <dc:creator>Lucas S Nogueira</dc:creator>
      <pubDate>Wed, 02 Feb 2022 14:55:43 +0000</pubDate>
      <link>https://forem.com/snlucas/minha-experiencia-frustrada-com-github-actions-e-aws-503m</link>
      <guid>https://forem.com/snlucas/minha-experiencia-frustrada-com-github-actions-e-aws-503m</guid>
      <description>&lt;p&gt;Durante quatro dias eu tentei fazer o CI/CD de uma aplicação que usaria AWS Lambda. Foram quatro dias frustrados.&lt;/p&gt;

&lt;p&gt;Minha aplicação era uma API com FastAPI. Para usar AWS Lambda em uma aplicação com FastAPI, eu não poderia usar Chalice (&lt;em&gt;&lt;a href="https://github.com/aws/chalice/issues/1427"&gt;according to this&lt;/a&gt;&lt;/em&gt;). Então, usei Mangum como &lt;em&gt;handler&lt;/em&gt; e S3 para enviar o projeto como .zip e este ser usado como função pelo Lambda.&lt;/p&gt;

&lt;p&gt;O problema aconteceu quando o Github tentou ler os secrets que eu adicionei como AWS credentials e isso simplesmente não funcionou. Tudo isso funciona em minha máquina com o credentials verificado.&lt;/p&gt;

&lt;p&gt;Enfim, minha opção será mudar o projeto para funcionar com o Chalice ao invés de FastAPI. Espero que haja suporte para FastAPI pelo Chalice no futuro. Mas, por enquanto, essa foi minha experiência.&lt;/p&gt;

</description>
      <category>githubactions</category>
      <category>aws</category>
    </item>
    <item>
      <title>Slides Sobre Sistemas Operacionais - Orbis OS</title>
      <dc:creator>Lucas S Nogueira</dc:creator>
      <pubDate>Tue, 25 Jan 2022 16:44:35 +0000</pubDate>
      <link>https://forem.com/snlucas/slides-sobre-sistemas-operacionais-orbis-os-c8m</link>
      <guid>https://forem.com/snlucas/slides-sobre-sistemas-operacionais-orbis-os-c8m</guid>
      <description>&lt;p&gt;Olá, pessoas.&lt;/p&gt;

&lt;p&gt;Essa é minha contribuição para quem está passando pela disciplina de Sistemas Operacionais.&lt;/p&gt;

&lt;p&gt;Eu tive a nota máxima para essa apresentação, então imagino que possa ser útil para alguém. Principalmente as referências.&lt;/p&gt;

&lt;p&gt;O sistema que usei para demonstrações práticas foi o Orbis OS. Aquele do Anime. Não foi bem escolha minha. Era isso ou o Qubes, e como não tinha muito tempo... 😅.&lt;/p&gt;

&lt;p&gt;Aconselho muito que seja utilizado outro sistema, como Ubuntu ou Elementary OS (que eu gosto bastante).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sourceforge.net/projects/orbisos/"&gt;link para download do Orbis&lt;/a&gt;&lt;br&gt;
&lt;a href="https://doragonden.wordpress.com/?s=orbis"&gt;link para o blog oficial do Orbis&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.slideshare.net/LucasNogueira565696/apresentao-sobre-sistemas-operacionais-com-orbis-os"&gt;link para os slides da apresentação&lt;/a&gt;&lt;/p&gt;

</description>
      <category>sistemasoperacionais</category>
      <category>linux</category>
      <category>orbisos</category>
    </item>
    <item>
      <title>Starting with FastAPI: Creating a Super Simple CRUD Exercise</title>
      <dc:creator>Lucas S Nogueira</dc:creator>
      <pubDate>Fri, 21 Jan 2022 16:47:04 +0000</pubDate>
      <link>https://forem.com/snlucas/starting-with-fastapi-creating-a-super-simple-crud-exercise-37a0</link>
      <guid>https://forem.com/snlucas/starting-with-fastapi-creating-a-super-simple-crud-exercise-37a0</guid>
      <description>&lt;p&gt;Hi, folks.&lt;br&gt;
This is my first post, and I'm super excited about it.&lt;/p&gt;

&lt;p&gt;I decided to learn FastAPI this week, and the first exercise that came to my mind was "a super simple CRUD app".&lt;/p&gt;

&lt;p&gt;It's super easy to do, and an easy way to start with FastAPI.&lt;/p&gt;

&lt;p&gt;First of all, notice that CRUD comes from &lt;strong&gt;C&lt;/strong&gt;reate, &lt;strong&gt;R&lt;/strong&gt;ead, &lt;strong&gt;U&lt;/strong&gt;pdate, and &lt;strong&gt;D&lt;/strong&gt;elete.&lt;/p&gt;

&lt;p&gt;Instead of a Database, I've decided to use operations with a simple Python dictionary.&lt;/p&gt;

&lt;p&gt;Let's start.&lt;/p&gt;

&lt;p&gt;Note. &lt;a href="https://github.com/snlucas/fapi-exercises" rel="noopener noreferrer"&gt;Link to the project on Github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;First, activate a 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;&lt;span class="nv"&gt;$ &lt;/span&gt;python3 &lt;span class="nt"&gt;-m&lt;/span&gt; venv .venv
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt; .venv/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, upgrade pip and install FastAPI, Pytest, Requests and Uvicorn.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-U&lt;/span&gt; pip fastapi pytest uvicorn requests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating the API
&lt;/h2&gt;

&lt;p&gt;In the &lt;a href="http://app.py/" rel="noopener noreferrer"&gt;app.py&lt;/a&gt; file (where is the API code), let's import FastAPI and its HTTPException class and status module.&lt;/p&gt;

&lt;p&gt;Use the app as a variable to FastAPI, and create a simple dictionary to handle our data.&lt;/p&gt;

&lt;p&gt;Notice the dictionary needs to be above the API methods (actually, above all methods that can use it).&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%2Fhyi02voxwojydbdgp0ig.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%2Fhyi02voxwojydbdgp0ig.png" alt="Importing FastAPI and creating a simple Python dictionary"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now is the time to create the CRUD functions.&lt;/p&gt;

&lt;p&gt;I decided to create a function to get all data, get data by id, delete data by id, delete all data, update, and create.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;C&lt;/strong&gt;reate
&lt;/h3&gt;

&lt;p&gt;Starting with the first CRUD letter. The C comes from Create.&lt;/p&gt;

&lt;p&gt;To create a message (simple string to add as a value to our dictionary) I needed to think about my endpoint (URL). I didn't want it to need a parameter more than the message itself. So I needed something like an autoincrement key.&lt;/p&gt;

&lt;p&gt;It's a simple task to do. We just need to concatenate the key string &lt;em&gt;message_&lt;/em&gt; with the number of our current index key. Our current index key is just the next key of our dictionary.&lt;br&gt;
So we just need to know the last key index and then increment. To do so, get the length of the dictionary and add 1. Update the next dictionary key with the new value.&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%2Fi3lyl8wqc2y7mp90rrlu.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%2Fi3lyl8wqc2y7mp90rrlu.png" alt="Create function"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;R&lt;/strong&gt;ead
&lt;/h3&gt;

&lt;p&gt;To get the messages I just need to verify if there's a message (data) in the dictionary. if it doesn't have any, raise an HTTP Exception informing this.&lt;/p&gt;

&lt;p&gt;I created two functions to handle the Read step:&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%2Fd42s57eng40j3vbqhwfe.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%2Fd42s57eng40j3vbqhwfe.png" alt="Read functions"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;U&lt;/strong&gt;pdate
&lt;/h3&gt;

&lt;p&gt;Almost done here. The update function needs the id (key) of the message and some data to update. Again, we need to be sure that we have a message with the passed id.&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%2Fxdq0jdig9lrskj5talx4.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%2Fxdq0jdig9lrskj5talx4.png" alt="Update function"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;D&lt;/strong&gt;elete
&lt;/h3&gt;

&lt;p&gt;The last step, finally.&lt;/p&gt;

&lt;p&gt;I created two functions here. One to delete by id and another one to delete all (the Metallica way).&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%2Fe6k818emv82tzkkddnhf.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%2Fe6k818emv82tzkkddnhf.png" alt="Delete functions"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Running
&lt;/h2&gt;

&lt;p&gt;To run our application just go to a terminal and type uvicorn pointing it to the file path (folder.subfolder_if_exists.file:fastapi_variable), followed of --reload.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;uvicorn app.exercise01.app:app &lt;span class="nt"&gt;--reload&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now it's time to take the tests. They're in my Github repository. Check it out.&lt;/p&gt;

&lt;p&gt;I hope this post helps you, and if you have any questions, pls make a comment.&lt;/p&gt;

</description>
      <category>fastapi</category>
      <category>python</category>
      <category>crud</category>
    </item>
  </channel>
</rss>
