<?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 João Paulo Pereira dos Santos on Medium]]></title>
        <description><![CDATA[Stories by João Paulo Pereira dos Santos on Medium]]></description>
        <link>https://medium.com/@joao.auhsey?source=rss-f0661a939ad1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WCTil6G_ZDFwJv3JOmbLsQ.jpeg</url>
            <title>Stories by João Paulo Pereira dos Santos on Medium</title>
            <link>https://medium.com/@joao.auhsey?source=rss-f0661a939ad1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 20:13:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@joao.auhsey/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[How to generate URLs with endpoints using Enum?]]></title>
            <link>https://medium.com/@joao.auhsey/how-to-generate-urls-with-endpoints-using-enum-6981bf7e173b?source=rss-f0661a939ad1------2</link>
            <guid isPermaLink="false">https://medium.com/p/6981bf7e173b</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[request]]></category>
            <category><![CDATA[endpoints]]></category>
            <category><![CDATA[url]]></category>
            <category><![CDATA[enum]]></category>
            <dc:creator><![CDATA[João Paulo Pereira dos Santos]]></dc:creator>
            <pubDate>Sat, 26 Sep 2020 00:35:35 GMT</pubDate>
            <atom:updated>2020-09-26T00:35:35.181Z</atom:updated>
            <content:encoded><![CDATA[<h4>An elegant approach to your requests</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V27zJ-ht66TTC2MQ5QYIUw.png" /></figure><h4>Why Enum?</h4><blockquote>“An <em>enumeration</em> defines a common type for a group of related values and enables you to work with those values in a type-safe way within your code.”</blockquote><p><em>The Swift Programming Language</em></p><p>With enums you can simplify the creation of urls for your requests. Have you ever imagined delegating the responsibility of generating URLs only to a specific layer of your application? Some already do it in other ways, today we are going to learn how to do it with Enums. Come on?</p><blockquote>Note: For this example, we will cover an application that <strong>manages product purchases</strong>, and in order not to take too long, our perspective will only be on the endpoints that refer to some entities involved in the purchase. Pay attention to the example and try to apply it according to your context and need.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0836bd39f634b8323c5dd3416479db3b/href">https://medium.com/media/0836bd39f634b8323c5dd3416479db3b/href</a></iframe><p>With these few lines of code, we can already use enums to help us with the creation of URLs. We would only have to know the base URL and perform a concatenation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/042d7ab092c48e3cdd6af5acae547d2d/href">https://medium.com/media/042d7ab092c48e3cdd6af5acae547d2d/href</a></iframe><p>But we want to go further, right? We will delegate to the enum all responsibility for generating a URL so that we only care about calling it, it magically returns what we want.</p><p>We can put a variable called url in the enum and make it aware of the Base URL…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5640fe16ef130d73e2a0eece1af31be0/href">https://medium.com/media/5640fe16ef130d73e2a0eece1af31be0/href</a></iframe><p>Very good! now we can see what the result is:</p><pre><strong>let</strong> productURL = PurchaseEndpoints.payment.url<br>//output: url = <a href="https://www.purchase.com/payment">https://www.purchase.com/payment</a></pre><p>If you are satisfied with this code thank you very much 😎❤️!</p><p>But I have news for you, which is good can get better 👀</p><p>What if you wanted to<strong> pass an id </strong>to generate this URL, and thus make a specific fetch with that id?</p><p>Let’s solve this!</p><h4>Creating a URL with ID</h4><p>To further organize our code we will first create a variable called fullPath, it will be responsible for concatenating elements and generating a complete string for our URL.</p><blockquote>Note: now we want a URL with this pattern: <a href="https://www.purchase.com/payment/2af5e340-6f6a-4c00-8544-4e12d95db985"><em>https://www.purchase.com/payment/2af5e340-6f6a-4c00-8544-4e12d95db985</em></a></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/742e0d851cf767a03779c7ef42141783/href">https://medium.com/media/742e0d851cf767a03779c7ef42141783/href</a></iframe><p>Nothing has changed. But we did this to insert new cases in our enum, cases that accept parameters. That’s right, you heard me right!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f41a86ca93920cc7e35ee088cd337f2/href">https://medium.com/media/8f41a86ca93920cc7e35ee088cd337f2/href</a></iframe><p>An enum call looks like this:</p><pre>let url = PurchaseEndpoints.paymentWith(id).url</pre><pre>// output: url = <a href="https://www.purchase.com/payment/F0F8A584-D83B-45DF-B2FE-78C9AE60A5C0">https://www.purchase.com/payment/F0F8A584-D83B-45DF-B2FE-78C9AE60A5C0</a></pre><p>There, now you have a more elegant way to instantiate your URLs. Share it with the community if you found it useful!</p><p>Thank you!</p><h4>References</h4><ul><li><a href="https://docs.swift.org/swift-book/LanguageGuide/Enumerations.html">Enumerations - The Swift Programming Language (Swift 5.7)</a></li><li><a href="https://medium.com/@PhiJay/why-swift-enums-with-associated-values-cannot-have-a-raw-value-21e41d5ec11">Why Swift Enums with Associated Values Cannot Have a Raw Value</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6981bf7e173b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Como gerar URLs com Endpoints usando Enum?]]></title>
            <link>https://medium.com/@joao.auhsey/como-gerar-urls-com-endpoints-usando-enum-383baefe67ed?source=rss-f0661a939ad1------2</link>
            <guid isPermaLink="false">https://medium.com/p/383baefe67ed</guid>
            <category><![CDATA[endpoints]]></category>
            <category><![CDATA[enum]]></category>
            <category><![CDATA[url]]></category>
            <category><![CDATA[request]]></category>
            <category><![CDATA[swif]]></category>
            <dc:creator><![CDATA[João Paulo Pereira dos Santos]]></dc:creator>
            <pubDate>Fri, 25 Sep 2020 18:44:18 GMT</pubDate>
            <atom:updated>2020-09-29T11:40:30.418Z</atom:updated>
            <content:encoded><![CDATA[<h4>Uma abordagem elegante sobre suas requisições</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V27zJ-ht66TTC2MQ5QYIUw.png" /></figure><h4><strong>Por que Enum?</strong></h4><blockquote>&quot;Uma enumeração define um tipo comum para um grupo de valores relacionados e permite que você trabalhe com esses valores de maneira segura para o tipo em seu código.&quot;</blockquote><p><em>The Swift Programming Language</em></p><p>Com enums você pode simplificar a criação de urls para suas requisições. Já imaginou delegar a responsabilidade de um gerar URLs apenas para uma camada específica de sua aplicação? Alguns já fazem isso de outras maneiras, hoje vamos aprender como fazê-lo com Enums. Vamos lá?</p><blockquote><strong>Nota :</strong> Para este exemplo iremos abordar uma aplicação que <strong>gerencia compras de produtos</strong>, e para não levarmos muito tempo, nossa perspectiva ficará apenas nos endpoints que se referem a algumas entidades envolvidas na compra. Se atente no exemplo e tente aplicá-lo conforme o seu contexto e necessidade.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0836bd39f634b8323c5dd3416479db3b/href">https://medium.com/media/0836bd39f634b8323c5dd3416479db3b/href</a></iframe><p>Com essas poucas linhas de código já podemos usar enums para nos auxiliar com a criação de URLs. Só teriamos que saber a URL base e realizar uma concatenação:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/042d7ab092c48e3cdd6af5acae547d2d/href">https://medium.com/media/042d7ab092c48e3cdd6af5acae547d2d/href</a></iframe><p>Mas queremos ir além, certo? Vamos delegar ao enum toda a responsabilidade de gerar uma URL de modo que só nos preocupemos em chamá-lo, em ele magicamente retorna o que queremos.</p><p>Podemos colocar no enum uma variável chamada url e fazer com que ele tenha conhecimento da URL Base …</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5640fe16ef130d73e2a0eece1af31be0/href">https://medium.com/media/5640fe16ef130d73e2a0eece1af31be0/href</a></iframe><p>Muito bom! agora podemos ver qual o resultado disso:</p><pre><strong>let</strong> productURL = PurchaseEndpoints.payment.url<br>//output: url = https://www.purchase.com/payment</pre><p>Se você está satisfeito com esse código muito obrigado 😎❤️!</p><p>Mas eu tenho uma notícia para você, o que é bom pode ficar melhor 👀</p><p>E se você quisesse <strong>passar um id</strong> para gerar essa url, e assim fazer um fetch específico com aquele id?</p><p>Vamos resolver isso!</p><h4>Criando uma URL com ID</h4><p>Para organizar ainda mais nosso código vamos primeiro criar uma variável chamada fullPath, ela será responsável por concatenar elementos e gerar uma string completa para nossa URL</p><blockquote><strong>Nota:</strong> agora queremos uma url com esse padrão: <em>https://www.purchase.com/payment/2af5e340-6f6a-4c00-8544-4e12d95db985</em></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/742e0d851cf767a03779c7ef42141783/href">https://medium.com/media/742e0d851cf767a03779c7ef42141783/href</a></iframe><p>Aparentemente nada mudou. Mas fizemos isso para inserir novos casos em nosso enum, casos que aceitam parâmetros. Isso mesmo, você ouviu bem!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f41a86ca93920cc7e35ee088cd337f2/href">https://medium.com/media/8f41a86ca93920cc7e35ee088cd337f2/href</a></iframe><p>A chamada do enum fica assim:</p><pre>let url = PurchaseEndpoints.paymentWith(id).url</pre><pre>// output: url = https://www.purchase.com/payment/F0F8A584-D83B-45DF-B2FE-78C9AE60A5C0</pre><p>Pronto, agora você tem uma maneira mais elegante de instanciar suas URLs. Compartilhe com a comunidade se achou útil!</p><p>Obrigado!</p><h4>Referências</h4><ul><li><a href="https://docs.swift.org/swift-book/LanguageGuide/Enumerations.html">Enumerations - The Swift Programming Language (Swift 5.7)</a></li><li><a href="https://medium.com/@PhiJay/why-swift-enums-with-associated-values-cannot-have-a-raw-value-21e41d5ec11">Why Swift Enums with Associated Values Cannot Have a Raw Value</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=383baefe67ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>