<?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: Flávio Ribeiro</title>
    <description>The latest articles on DEV Community by Flávio Ribeiro (@fullstackwizard).</description>
    <link>https://dev.to/fullstackwizard</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%2F133352%2F3f83b946-7672-4e92-abb9-3ed93f3a31e6.jpeg</url>
      <title>DEV Community: Flávio Ribeiro</title>
      <link>https://dev.to/fullstackwizard</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fullstackwizard"/>
    <language>en</language>
    <item>
      <title>Diferença entre Dependency Injection e Service Locator em C#</title>
      <dc:creator>Flávio Ribeiro</dc:creator>
      <pubDate>Fri, 21 Mar 2025 12:35:34 +0000</pubDate>
      <link>https://dev.to/fullstackwizard/diferenca-entre-dependency-injection-e-service-locator-em-c-ii6</link>
      <guid>https://dev.to/fullstackwizard/diferenca-entre-dependency-injection-e-service-locator-em-c-ii6</guid>
      <description>&lt;h2&gt;
  
  
  Diferença entre Dependency Injection e Service Locator
&lt;/h2&gt;

&lt;p&gt;A injeção de dependência (Dependency Injection - DI) e o localizador de serviço (Service Locator - SL) são padrões utilizados para gerenciar dependências em aplicações C#. Ambos ajudam a desacoplar componentes, mas funcionam de maneiras diferentes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dependency Injection (DI)
&lt;/h2&gt;

&lt;p&gt;A Dependency Injection é um padrão que permite que dependências sejam passadas para uma classe em vez de serem instanciadas dentro dela. Isso melhora a testabilidade, manutenção e extensibilidade do código.&lt;/p&gt;

&lt;h3&gt;
  
  
  Exemplo de Dependency Injection
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Interface do Serviço&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;IEmailService&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;SendEmail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Implementação do Serviço&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;EmailService&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IEmailService&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;SendEmail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"Email enviado: &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;message&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="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Classe que recebe a dependência via construtor&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;NotificationService&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;IEmailService&lt;/span&gt; &lt;span class="n"&gt;_emailService&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;NotificationService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IEmailService&lt;/span&gt; &lt;span class="n"&gt;emailService&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_emailService&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;emailService&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_emailService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SendEmail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Configuração do Dependency Injection&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;serviceProvider&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ServiceCollection&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddScoped&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IEmailService&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;EmailService&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;BuildServiceProvider&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Resolvendo a dependência&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;notificationService&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;NotificationService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;serviceProvider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetRequiredService&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IEmailService&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;());&lt;/span&gt;
&lt;span class="n"&gt;notificationService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Olá, DI!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Service Locator (SL)
&lt;/h2&gt;

&lt;p&gt;O padrão Service Locator usa um contêiner global para gerenciar e recuperar dependências. Embora facilite a resolução dinâmica de serviços, pode dificultar testes e depuração, pois cria um forte acoplamento com o contêiner de injeção.&lt;/p&gt;

&lt;h3&gt;
  
  
  Exemplo de Service Locator
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ServiceLocator&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;IServiceProvider&lt;/span&gt; &lt;span class="n"&gt;_serviceProvider&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;SetLocator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IServiceProvider&lt;/span&gt; &lt;span class="n"&gt;serviceProvider&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_serviceProvider&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;serviceProvider&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;T&lt;/span&gt; &lt;span class="n"&gt;GetService&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_serviceProvider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetRequiredService&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Configuração do contêiner&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;serviceProvider&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ServiceCollection&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddScoped&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IEmailService&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;EmailService&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;BuildServiceProvider&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;ServiceLocator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SetLocator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;serviceProvider&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Resolvendo a dependência via Service Locator&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;emailService&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ServiceLocator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetService&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IEmailService&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
&lt;span class="n"&gt;emailService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SendEmail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Olá, SL!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Comparando Dependency Injection e Service Locator
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Critério&lt;/th&gt;
&lt;th&gt;Dependency Injection&lt;/th&gt;
&lt;th&gt;Service Locator&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Acoplamento&lt;/td&gt;
&lt;td&gt;Baixo&lt;/td&gt;
&lt;td&gt;Alto&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Testabilidade&lt;/td&gt;
&lt;td&gt;Melhor&lt;/td&gt;
&lt;td&gt;Difícil&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Facilidade de uso&lt;/td&gt;
&lt;td&gt;Pode requerer configuração&lt;/td&gt;
&lt;td&gt;Fácil de usar&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Manutenção&lt;/td&gt;
&lt;td&gt;Melhor para evolução&lt;/td&gt;
&lt;td&gt;Pode dificultar depuração&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Snippet Exclusivo - Comparando os Dois Padrões
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Program&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;services&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ServiceCollection&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddScoped&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IEmailService&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;EmailService&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;()&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;BuildServiceProvider&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Dependency Injection&lt;/span&gt;
        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;notificationServiceDI&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;NotificationService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetRequiredService&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IEmailService&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;());&lt;/span&gt;
        &lt;span class="n"&gt;notificationServiceDI&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Usando Dependency Injection"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Service Locator&lt;/span&gt;
        &lt;span class="n"&gt;ServiceLocator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SetLocator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;emailServiceSL&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ServiceLocator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetService&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IEmailService&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
        &lt;span class="n"&gt;emailServiceSL&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SendEmail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Usando Service Locator"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusão
&lt;/h2&gt;

&lt;p&gt;Embora ambos os padrões possam ser usados, a Dependency Injection é preferida por proporcionar menor acoplamento e maior testabilidade. O Service Locator pode ser útil em cenários específicos, mas seu uso excessivo pode levar a dificuldades na manutenção do código. Escolha o padrão que melhor atende às necessidades do seu projeto!&lt;/p&gt;

</description>
      <category>csharp</category>
    </item>
    <item>
      <title>Artigo Curl API (GET/POST/PUT/DELETE)</title>
      <dc:creator>Flávio Ribeiro</dc:creator>
      <pubDate>Sat, 22 Feb 2020 11:17:52 +0000</pubDate>
      <link>https://dev.to/fullstackwizard/artigo-curl-api-get-post-put-delete-fn9</link>
      <guid>https://dev.to/fullstackwizard/artigo-curl-api-get-post-put-delete-fn9</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fginykp2f2b0h6ylavj8r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fginykp2f2b0h6ylavj8r.png" alt="Alt Text" width="700" height="264"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Chamadas da API cURL com dados PHP e json (GET POST PUT DELETE)
&lt;/h1&gt;

&lt;p&gt;Recentemente surgiu uma task em um projeto compartilhado com um grupo de programadores, consumir uma API Rest externa usando solicitações HTTP cURL em um simples projeto, eu já havia lido sobre, até tinha feito algumas usando outras APIs, mas com a falta de pratica acabamos não lembrando, escrevo esse artigo mais para eu poder me lembrar das chamadas que aprendi nos estudos e poder ajudar vocês. &lt;/p&gt;

&lt;h1&gt;
  
  
  Curl Simples
&lt;/h1&gt;

&lt;p&gt;Para implementar uma simples API no projeto você pode usar algumas simples chamadas:&lt;/p&gt;

&lt;pre&gt;



```

$url = "https://reqres.in/api/users?page=2";
$ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $response = curl_exec($ch);
        curl_close($ch);

$users = json_decode($response, true);
$user = $users['data']; 

```



&lt;/pre&gt;

&lt;p&gt;Nesse caso, o código vai consumir os dados do array contidos na page $url e depois transforma em json através do json_decode(), usar true para ele validar o array, assim facilitando o retorno.&lt;/p&gt;

&lt;h1&gt;
  
  
  cURL Composto com os Requests
&lt;/h1&gt;

&lt;p&gt;Mas vamos nos aprofundar mais criando scripts PHP que permite chamar essa função, como um conjunto de parâmetros, para que a solicitação cURL seja feita e você possa usar o codigo para qualquer tipo de API-HTTP.&lt;/p&gt;

&lt;p&gt;&lt;b&gt; - Coloque o arquivo da função geral que possa ser acessado por todo o projeto.&lt;/b&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;app/module 
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;



```

 function pullAPI($param1, $uri, $data){
   $curl = curl_init();
   switch ($param1){
      case "POST":
         curl_setopt($curl, CURLOPT_POST, 1);
         if ($data)
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
         break;
      case "PUT":
         curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
         if ($data)
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);                              
         break;
      default:
         if ($data)
            $uri = sprintf("%s?%s", $uri, http_build_query($data));
   }
   // OPTIONS:
   curl_setopt($curl, CURLOPT_URL, $uri);
   curl_setopt($curl, CURLOPT_HTTPHEADER, array(
      'APIKEY: 111111111111111111111',
      'Content-Type: application/json',
   ));
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
   // EXECUTE:
   $result = curl_exec($curl);
   if(!$result){die("Connection Failure");}
   curl_close($curl);
   return $result;
}

```



&lt;/pre&gt;

&lt;p&gt;Está função é simples, usando uma instrução SWITCH para verificar se a chamada da API será por POST ou PUT, até mesmo GET ou DELETE, vou me aprofundar mais no caso de troca enquanto estamos realizando solicitações específicas.  &lt;/p&gt;

&lt;p&gt;Estou usando if dentro dos blocos de SWITCH para fornecer dados json em nossa chamada ou não .. $data = dados json. Para solicitar POST e PUT a instrução if não é realmente necessária, porque estamos usando apenas POST ou PUT como dados, mas é uma segurança para garantira que nossa função não seja interrompida &lt;/p&gt;

&lt;p&gt;# Criando a chamada GET &lt;/p&gt;

&lt;p&gt;A chamada mais simples é a GET, então vamos lá .. nessa nossa função pullAPI esperamos três parâmetros $param1, $uri, e a $data, precisamos fornecer esses três para todas as chamadas de API, então podemos definir o $data como false, pois não estamos transmitindo nenhum dado com a chamada GET, agora no arquivo index.php na raiz do projeto vamos fazer uma chamada passando os 3 parâmetros de uma API qualquer, usaremos a API da reqres.in como exemplo. &lt;/p&gt;

&lt;p&gt;Primeiro faça a chamada do arquivo da função pullAPI &lt;/p&gt;

&lt;pre&gt;



```

require_once('app/modules/reqres.api.php');

```



&lt;/pre&gt;

&lt;p&gt;Depois vamos chamar o método GET.&lt;/p&gt;

&lt;pre&gt;



```

$get_data = pullAPI('GET', 'https://reqres.in/api/users?page=2', false);
$get_users = json_decode($get_data, true);

// parametros de erros 
$errors = $get_users['get_users']['erros'];
// patametros de arrays usabeis no php
$data = $get_users['response']['data']['0'];
&lt;/pre&gt;

&lt;p&gt;A função setada na variavel $get_data , pullAPI passa 3 parâmetros, qual o metodo = GET , a url '&lt;a href="https://reqres.in/api/users" rel="noopener noreferrer"&gt;https://reqres.in/api/users&lt;/a&gt;' e o data como não está passando nenhum dado, passamos 'false' como parâmetro.&lt;/p&gt;

&lt;p&gt;Para testar o código de um &lt;code&gt;print_r($get_users);&lt;/code&gt; para ver o retorno em tela.  &lt;/p&gt;

&lt;h1&gt;
  
  
  Criando a chamada Post
&lt;/h1&gt;

&lt;p&gt;A Solicitação POST requer dados, por isso temos que passar os 3 parâmetros ao final, como nesse método vamos enviar dados é obrigatório passar o parâmetro que será enviado, no local de $data que é o ultimo parâmetro vamos criar um array com os dados a ser enviados como POST.&lt;/p&gt;

&lt;pre&gt;

```



array(
    'id' =&amp;gt; '13',
    'first_name' =&amp;gt; 'firstname',
    'last_name' =&amp;gt; 'lastname',
    'email' =&amp;gt; 'email@email.com.br',
    'avatar' =&amp;gt; 'linkdoavatar.com.br/link.jpg'
);
&lt;/pre&gt;
 

&lt;p&gt;podemos setar isso em uma variável $data_array , ficando o código assim, chamando a função com os 3 parâmetros e retornando o json.&lt;/p&gt;

&lt;pre&gt;



```

 $data_array = array(
    'id' =&amp;gt; '16',
    'first_name' =&amp;gt; 'flavio',
    'last_name' =&amp;gt; 'ribeiro',
    'email' =&amp;gt; 'devflavioribeiro@gmail.com',
);
$make_call = pullAPI('POST', 'https://reqres.in/api/users', json_encode($data_array));
$response = json_decode($make_call, true);
&lt;/pre&gt;

&lt;p&gt;ao rodar var_dump($response);&lt;br&gt;
Retorna o json a ser enviado com método Post.&lt;/p&gt;

&lt;h1&gt;
  
  
  Criando a chamada PUT
&lt;/h1&gt;

&lt;p&gt;A Solicitação de PUT é a mesma que a do Post, a diferença é que o PUT é uma envio mais específico, e usada quando desejamos enviar somente a informação a ser armazenada, podemos usar os mesmos parâmetros do Post. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Nesse caso agora vamos transformar nossa passagem de parâmetro personalizada para realização de um UPDATE.&lt;/li&gt;
&lt;li&gt;Mais detalhado para depois jogar tudo dentro das funções corretamente, mas vamos passo a passo para aprender a linha de raciocínio ao desenvolver o código. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Com o PUT podemos usar a base da estrutura de array do POST, a diferença agora que vamos passar variáveis por parâmetro dentro do array. &lt;/p&gt;

&lt;pre&gt;

```



$id = '6';
$email = 'devflavioribeiro@gmail.com';
$first_name = 'Flavio';
$last_name  = 'Ribeiro'; 
$avatar = 'http://flavioAPI.com.br/img.jpg';
&lt;/pre&gt;

&lt;p&gt;Logo após criamos o array associativo para dar UPDATE:&lt;/p&gt;

&lt;pre&gt;



```

$data_array =  array(
    'id' =&amp;gt; $id,
    'email' =&amp;gt; $email,
    'first_name' =&amp;gt; $first_name,
    'last_name' =&amp;gt; $last_name,
    'avatar' =&amp;gt; $avatar
 );
&lt;/pre&gt;

&lt;p&gt;Assim vamos usar a mesma chamada da função pullAPI passando novamente 3 parâmetros mas dessa vez com uma diferença, pois como é um UPDATE ele deve conter no URL uma concatenação de uma variável para definir qual o usuário que esta fazendo o update, então no codigo fica assim:&lt;/p&gt;

&lt;pre&gt;

```



$update_plan = pullAPI('PUT', 'https://reqres.in/api/users/' . $id, json_encode($data_array));
$response = json_decode($update_plan, true);
&lt;/pre&gt;

&lt;h1&gt;
  
  
  Criando a chamada DELETE
&lt;/h1&gt;

&lt;p&gt;Ultimo método é o DELETE, que é a solicitação de exclusão bem simples, nesse caso é necessário aplicar na URL qual o $id que vamos deletar, não sendo necessário passar ele por array, então o código fica assim:&lt;/p&gt;

&lt;pre&gt;



```



$id = '3';
$delete_user = pullAPI('DELETE', 'https://reqres.in/api/users/' . $id, false);
$usuariodeletado = json_decode($delete_user, true);


if(isset($delete_user)){
    echo "O Usuário " . $usuariodeletado['data']['first_name'] . " Foi deletado" . "&lt;br&gt;";
}else {
    echo "Usuário não encontrado";
}
&lt;/pre&gt;

&lt;p&gt;Então na variável $id podemos colocar o id do usuário que vai ser deletado, chamamos a classe , passamos os 3 parâmetros, como não estamos enviando dados, usamos o 'false' no ultimo parâmetro, e fazemos uma validação do $delete_user para saber qual o usuário que deletamos, usei somente o 'first_name' mas podemos usar toda as informações da lista do json. &lt;/p&gt;

&lt;p&gt;Aqui foi uma breve explicação de como criar uma classe automatizada para consumir uma API cURL com os dados em Json usando PHP, aqui temos uma gama de modificações para fazer , podemos criar funções usando esse parâmetros para cada método, mas quis fazer de uma forma simples e rápida, com uma didática limpa, espero que tenham gostado. &lt;/p&gt;




&lt;p&gt;Author&lt;br&gt;
Flávio Ribeiro&lt;br&gt;
Desenvolvedor Web&lt;/p&gt;

</description>
      <category>php</category>
      <category>curl</category>
      <category>poo</category>
      <category>phppure</category>
    </item>
    <item>
      <title>5 Tips for Landing Consistent Work as a Freelance Front-End Web Developer</title>
      <dc:creator>Flávio Ribeiro</dc:creator>
      <pubDate>Wed, 27 Feb 2019 20:51:54 +0000</pubDate>
      <link>https://dev.to/fullstackwizard/5-tips-for-landing-consistent-work-as-a-freelance-front-end-web-developer-4d10</link>
      <guid>https://dev.to/fullstackwizard/5-tips-for-landing-consistent-work-as-a-freelance-front-end-web-developer-4d10</guid>
      <description>&lt;p&gt;No alarm clock. No dress code. No inane watercooler gossip. No boss!&lt;/p&gt;

&lt;p&gt;The freelance life is pretty, well, freeing. You get to choose the projects you work on, establish your own schedule, and set your own standards of excellence.&lt;/p&gt;

&lt;p&gt;Creative careers of all sorts often include &lt;a href="http://blog.udacity.com/2014/09/front-end-web-development-freelancing-vs-full-time" rel="noopener noreferrer"&gt;freelancing&lt;/a&gt; in some capacity. At some point in your career as a &lt;a href="https://www.udacity.com/course/front-end-web-developer-nanodegree--nd001" rel="noopener noreferrer"&gt;front end developer&lt;/a&gt;, either on the side or as your full-time pursuit, you’ll likely find yourself in search of freelance work.&lt;/p&gt;

&lt;p&gt;As with any endeavor, there are upsides and downsides to self-employment (take a look at &lt;a href="http://blog.udacity.com/2014/09/front-end-web-development-freelancing-vs-full-time" rel="noopener noreferrer"&gt;this Freelancing vs. Full Time post&lt;/a&gt; for a thorough rundown). But there’s one indisputable aspect to freelancing: you want to attract consistent work.&lt;/p&gt;

&lt;p&gt;How exactly do you do that? Here are five best practices for situating yourself to attract regular work as a freelancer.&lt;/p&gt;

&lt;h2&gt;Maintain a Stellar Portfolio&lt;/h2&gt;

&lt;p&gt;As a freelancer, your portfolio is your number one selling tool. &lt;a href="https://github.com/" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;, &lt;a href="https://www.behance.net/" rel="noopener noreferrer"&gt;Behance&lt;/a&gt;, or a &lt;a href="http://www.creativebloq.com/portfolios/examples-712368" rel="noopener noreferrer"&gt;beautiful personal website&lt;/a&gt; are all strong options for housing your portfolio. Use your collection of work as an opportunity to reflect your personal brand and to cleanly showcase your best stuff.&lt;/p&gt;

&lt;p&gt;Not sure what to include? Remember that anyone viewing your portfolio will be making a snap impression, and you want them to get a feel for the spectrum of projects you’ve done, so feature a curated but wide range of work.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;&lt;span&gt;There’s no time like the present to start setting yourself up for freelance success.&lt;a href="http://twitter.com/intent/tweet?url=https://blog.udacity.com/2014/11/5-tips-for-landing-consistent-work-as.html&amp;amp;text=There%E2%80%99s%20no%20time%20like%20the%20present%20to%20start%20setting%20yourself%20up%20for%20freelance%20success.&amp;amp;related=udacity&amp;amp;hashtags=front-end%20web%20dev," title="Tweet this!" rel="noopener noreferrer"&gt; tweet&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;No professional projects to your name yet? If you have something stellar to show from a course, that’ll work, but be picky: you’re in constant competition against other, more experienced developers. It can also be helpful, once you’ve got the skills down, to offer to complete some work for free, or for cheap, for friends and acquaintances, in order to flex those freelance muscles and secure some strong work examples.&lt;/p&gt;

&lt;h2&gt;Leverage Twitter as a Networking Tool&lt;/h2&gt;

&lt;p&gt;Twitter can be an extremely powerful professional instrument if you use it to its fullest potential. A few tips:&lt;/p&gt;


&lt;ul&gt;

&lt;li&gt;

&lt;b&gt;&lt;em&gt;Search relevant phrases and hashtags&lt;/em&gt;:&lt;/b&gt; Put Twitter’s search engine to work. Regularly search for the latest conversations around industry topics, companies you have your eye on, and developers you respect (you can follow them directly if they’re on Twitter, but searching for them surfaces all the content &lt;em&gt;about&lt;/em&gt; them from other Twitter users globally). Drill down for the most targeted results using advanced filters like sentiment, location, and dates; access the advanced search tools by typing in a search string, then clicking Advanced Search on the results page. Search on relevant words and phrases, both with and without hashtags. You can even save searches in Twitter for quick access.&lt;/li&gt;

&lt;li&gt;

&lt;b&gt;&lt;em&gt;Join industry Twitter chats to connect with other developers and potential clients&lt;/em&gt;:&lt;/b&gt; Chiming in on Twitter chats lets you engage in real time with hyper-relevant contacts, those who offer the most bang for your networking buck. &lt;a href="https://twitter.com/@frontiergroup" rel="noopener noreferrer"&gt;The Frontier Group&lt;/a&gt;, for example, hosts a monthly Friday #NewWebFrontier chat from 8 to 9 p.m. EST.&lt;/li&gt;

&lt;li&gt;

&lt;b&gt;&lt;em&gt;Follow lists and form your own&lt;/em&gt;:&lt;/b&gt; Twitter lists are an underutilized networking tool. As you discover useful or interesting accounts, categorize them into lists to keep track of who you’d like to reach out to or stay in touch with. Lists can be made private (but they’re public by default; make sure you toggle the setting to private), so feel free to label them as you see fit. Categories could include “new clients to pitch,” “useful connections of friends,” and the like. You can also follow other Twitter users’ public lists if you think they’re helpful.&lt;/li&gt;

&lt;li&gt;

&lt;b&gt;&lt;em&gt;Browse your followers’ followers (and the followers of people you’re following)&lt;/em&gt;: &lt;/b&gt;The best way to find the most helpful people to follow on Twitter is to explore who’s following, and being followed by, users you already admire. As you find promising leads, add them to your lists!&lt;/li&gt;

&lt;/ul&gt;
&lt;h2&gt;Get Active on LinkedIn&lt;/h2&gt;

&lt;p&gt;When you’re searching for consistent freelance work, LinkedIn is your most valuable tool for rubbing virtual elbows with potential clients, and for impressing past and current clients so they’ll want to hire you again. A few helpful hints:&lt;/p&gt;


&lt;ul&gt;

&lt;li&gt;

&lt;b&gt;&lt;em&gt;Keep your work history up to date&lt;/em&gt;:&lt;/b&gt; Just as you should always keep your resume current, you should also keep your LinkedIn profile current. And don’t forget to write a succinct, catchy summary of your background: it’s the first thing people see after your photo and thumbnail sketch of job titles.&lt;/li&gt;

&lt;li&gt;

&lt;b&gt;&lt;em&gt;Upload work examples&lt;/em&gt;:&lt;/b&gt; Let your work do the talking. Upload files or include links in your Summary or Projects sections that illustrate your experience. The more compelling your profile, the more likely someone is to reach out. Select a few top-notch pieces from your portfolio, and then link to the full site in your summary—don’t replicate your entire portfolio.&lt;/li&gt;

&lt;li&gt;

&lt;b&gt;&lt;em&gt;Utilize the site’s social networking component&lt;/em&gt;:&lt;/b&gt; Post interesting articles, and share, like, or comment on the articles posted by others. It’s a quick and easy way to form new connections, or keep old ones alive. You can even track how many views or likes these posts and shares get, to gauge how much traction your LinkedIn networking is gaining.&lt;/li&gt;

&lt;li&gt;

&lt;b&gt;&lt;em&gt;Join and participate in relevant groups&lt;/em&gt;:&lt;/b&gt; LinkedIn groups have amazing networking potential. Sharing a group membership with a key contact enables you to message each other even if you’re not officially “linked” on the site (don’t forget to configure your settings within the group to enable direct messaging). &lt;a href="https://www.linkedin.com/grp/" rel="noopener noreferrer"&gt;Search for groups&lt;/a&gt; that appeal to you, request membership or enlist directly (some are open, some require approval for entry), and then join the conversation to powwow with industry peers and promising leads.&lt;/li&gt;

&lt;li&gt;

&lt;b&gt;&lt;em&gt;Ask (politely) for recommendations&lt;/em&gt;:&lt;/b&gt; Advocate for yourself by tactfully requesting a recommendation from a former colleague, manager, or client. You can do so formally via LinkedIn, or through an email, phone call, or in-person conversation. You could also take the initiative and recognize a valued connection with a recommendation, tacitly requesting one in return.&lt;/li&gt;

&lt;li&gt;

&lt;b&gt;&lt;em&gt;Examine your connections’ connections&lt;/em&gt;:&lt;/b&gt; A warm introduction to a desired client from someone who knows both of you is far more likely to land you work than a cold call. Browse through the people connected to the people &lt;em&gt;you’re&lt;/em&gt; connected to. You never know who you might meet.&lt;/li&gt;

&lt;/ul&gt;
&lt;h2&gt;Tap into Job Boards&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://blog.udacity.com/2014/09/front-end-web-development-freelancing-vs-full-time" rel="noopener noreferrer"&gt;Job listing hubs&lt;/a&gt; like &lt;a href="http://www.guru.com/" rel="noopener noreferrer"&gt;Guru&lt;/a&gt;, &lt;a href="https://gun.io/" rel="noopener noreferrer"&gt;Gun.io&lt;/a&gt;, &lt;a href="https://www.elance.com/" rel="noopener noreferrer"&gt;Elance.com&lt;/a&gt;, &lt;a href="https://www.behance.net/joblist" rel="noopener noreferrer"&gt;Behance’s job search&lt;/a&gt;, &lt;a href="http://careers.stackoverflow.com/jobs" rel="noopener noreferrer"&gt;Stack Overflow&lt;/a&gt;, &lt;a href="https://jobs.github.com/" rel="noopener noreferrer"&gt;GitHub Jobs&lt;/a&gt;, and the Jobs section on &lt;a href="http://www.craigslist.org/" rel="noopener noreferrer"&gt;Craigslist&lt;/a&gt; can be reliable resources for finding steady freelance work. Be sure to present yourself professionally when you apply for gigs (no typos!), and apply only to jobs you are well-qualified for.&lt;/p&gt;

&lt;p&gt;One major caveat: use job boards mainly as a complement to other tools for locking down freelance work. There’s a lot of chaff to wade through to get to the wheat, and you’re always more likely to find high-quality opportunities when they’re coming directly from people you know.&lt;/p&gt;

&lt;h2&gt;Be Amazing to Work With&lt;/h2&gt;

&lt;p&gt;Most important of all, once you’ve landed the work, deliver. The best business is return business. Repeat clients are more likely to increase your rate; to refer others to you; and to be enjoyable to work for, since you have a higher likelihood of establishing a rapport.&lt;/p&gt;

&lt;p&gt;How to attract repeat clients? In addition to the hard skills, nurture your &lt;a href="http://blog.udacity.com/2014/11/4-soft-skills-that-will-get-you-the-job-and-keep-you-there" rel="noopener noreferrer"&gt;soft skills&lt;/a&gt;. That means being a strong communicator, being detail-oriented, and being adaptable and efficient. Always deliver your work on time and, of course, make sure that the finished product aligns closely with client expectations. You want to complete a project with the feeling that both you and the client would consider it ideal to work together again.&lt;/p&gt;

&lt;h2&gt;The Bottom Line&lt;/h2&gt;

&lt;p&gt;In 2014, &lt;a href="https://www.freelancersunion.org/blog/2014/09/12/how-many-freelancers-are-there-america-53-million/" rel="noopener noreferrer"&gt;34% of the workforce&lt;/a&gt; freelances. That prevalence suggests that you’re more likely than not to be in search of work by contract at some point in your career, and more likely than not to find it when you want it.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
