<?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: Cloudways</title>
    <description>The latest articles on Forem by Cloudways (@cloudways).</description>
    <link>https://forem.com/cloudways</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%2F1248%2Fcw-logo-icon__1_.png</url>
      <title>Forem: Cloudways</title>
      <link>https://forem.com/cloudways</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/cloudways"/>
    <language>en</language>
    <item>
      <title>Installing Symfony 3.x on DigitalOcean</title>
      <dc:creator>Cloudways</dc:creator>
      <pubDate>Thu, 18 May 2017 12:54:35 +0000</pubDate>
      <link>https://forem.com/cloudways/installing-symfony-3x-on-digitalocean</link>
      <guid>https://forem.com/cloudways/installing-symfony-3x-on-digitalocean</guid>
      <description>&lt;p&gt;&lt;em&gt;This article was originally published at Cloudways: &lt;a href="https://www.cloudways.com/blog/install-symfony-3-on-cloud/" rel="noopener noreferrer"&gt;How To Install Symfony 3 On Cloud Server&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Symfony is the leading, modern PHP framework that is used to create secure websites and web applications with the help of its different components. It’s a popular MVC framework which saves time with handling typical development tasks such as content rendering, directing traffic, creating persistent models, etc.&lt;/p&gt;

&lt;p&gt;To install and run Symfony 3, your system needs to fulfill a list of following requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PHP with a minimum version of 5.5.9&lt;/li&gt;
&lt;li&gt;Composer&lt;/li&gt;
&lt;li&gt;JSON enabled&lt;/li&gt;
&lt;li&gt;ctype enabled&lt;/li&gt;
&lt;li&gt;date.timezone should be set (default timezone will not work)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note: If you want to use any optional component, see these &lt;a href="http://symfony.com/doc/current/reference/requirements.html" rel="noopener noreferrer"&gt;Requirements for Running Symfony&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you are wondering how to install Symfony on Cloudways, you can simply follow this easy step-by-step guide. Ready? Lets begin!&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Prepare your server and application
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://platform.cloudways.com/signup" rel="noopener noreferrer"&gt;Signup or Login to your Cloudways account&lt;/a&gt; and create a new server by selecting PHP Stack from the &lt;strong&gt;“Select your Application”&lt;/strong&gt; drop-down. Also, Name your App, Server &amp;amp; Project accordingly.&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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fselect-application.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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fselect-application.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Select Cloud Provider
&lt;/h2&gt;

&lt;p&gt;Now select your favorite Cloud provider.&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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fselect-cloud-provider-1.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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fselect-cloud-provider-1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Server Size and Location
&lt;/h2&gt;

&lt;p&gt;In “Server Size” field, scale up to 1GB.&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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fserver-size.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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fserver-size.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Keeping the latency difference in mind, now select your server location in “Location” field.&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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fserver-location.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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fserver-location.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To launch your server, click “Launch” button at the bottom right side of the page and wait for a while. A working example:&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/http%3A%2F%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fphp-server-stack.gif" 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/http%3A%2F%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fphp-server-stack.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Server Timezone
&lt;/h2&gt;

&lt;p&gt;Once launched, change your server timezone as it’s the requirement to install Symfony (default value for timezone is not supported by Symfony). Under &lt;strong&gt;“Server Management”&lt;/strong&gt;, go to &lt;em&gt;“Settings &amp;amp; Packages.”&lt;/em&gt;*&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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fserver-management.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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fserver-management.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;“Basic”&lt;/strong&gt; tab you can see &lt;strong&gt;“PHP Timezone.”&lt;/strong&gt; Change server timezone to your respective location.&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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fserver-timezone-1.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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fserver-timezone-1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: SSH Terminal
&lt;/h2&gt;

&lt;p&gt;After changing server timezone, in “Server Management” click on “Launch SSH Terminal” under “Master Credentials” where you can find your login credentials for SSH Terminal.&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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fmaster-credentials.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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fmaster-credentials.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Login to SSH with your Master Credentials.&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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fsymfony-7.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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fsymfony-7.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Emptying public_html directory
&lt;/h2&gt;

&lt;p&gt;Now delete all files from your public_html directory. Navigate to your public_html folder and remove all files using &lt;code&gt;rm -Rf *&lt;/code&gt; command.&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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fsymfony-8.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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fsymfony-8.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Symfony 3 Installation
&lt;/h2&gt;

&lt;p&gt;Now in your “public_html” directory, run the following command to install Symfony 3 on your server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer create-project symfony/framework-standard-edition your_project_name "3.0.*"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fsymfony-9-768x54.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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fsymfony-9-768x54.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;for 3.1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer create-project symfony/framework-standard-edition your_project_name "3.1"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 8: DB Information and Finishing Project Installation
&lt;/h2&gt;

&lt;p&gt;Now Symfony will start downloading to your server. During downloading, it will ask for your database information.&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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fsymfony-10-768x341.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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fsymfony-10-768x341.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find out your DB information under &lt;em&gt;“Application Management”&lt;/em&gt; go to &lt;strong&gt;“Access detail”&lt;/strong&gt; and see &lt;strong&gt;MySQL Access&lt;/strong&gt;.&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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2FMySQL-access.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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2FMySQL-access.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After providing database information, in very few seconds you will see the following screen which means that Symfony has been installed successfully.&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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fsymfony-11.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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fsymfony-11.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 9: Composer Repositories
&lt;/h2&gt;

&lt;p&gt;Now we will check if there is any need to install or update composer dependencies required for the application by using &lt;code&gt;composer install&lt;/code&gt; command. Navigate to your project directory and run the command.&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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fsymfony-12-768x481.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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fsymfony-12-768x481.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 10: Installation Completed
&lt;/h2&gt;

&lt;p&gt;After a successful installation, in “Application Management” go to “Access detail” and copy your Application URL.&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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2FMySQL-access.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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2FMySQL-access.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open your favorite web browser and access to Welcome page to Symfony by the following URL:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://your_application_url/your_project_directory/web" rel="noopener noreferrer"&gt;http://your_application_url/your_project_directory/web&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is how the Symfony Welcome page should look like:&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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fsymfony-14-768x409.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%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2Fsymfony-14-768x409.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There you have it! Your Symfony Project is ready for development. If you have any issues in installing Symfony 3, feel free to comment below. And if you are still not a part of the Cloudways family, then you can start your FREE TRIAL here and experience ease at its best.&lt;/p&gt;

</description>
      <category>digitalocean</category>
      <category>symfony</category>
      <category>php</category>
      <category>symfonydigitalocean</category>
    </item>
    <item>
      <title>Consuming Restful API in PHP with Guzzle</title>
      <dc:creator>Cloudways</dc:creator>
      <pubDate>Wed, 26 Apr 2017 12:51:55 +0000</pubDate>
      <link>https://forem.com/cloudways/consuming-restful-api-in-php-with-guzzle</link>
      <guid>https://forem.com/cloudways/consuming-restful-api-in-php-with-guzzle</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally Published at &lt;a href="https://hackernoon.com/creating-rest-api-in-php-using-guzzle-d6a890499b02" rel="noopener noreferrer"&gt;HackerNoon.com&lt;/a&gt; on April 18, 2017&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you are familiar with Rest API, you must know about HTTP calls created for getting and posting data from the client to the server. What if you wish to create a REST API client in PHP? Your answer would be to go with CURL. CURL is the most widely used method to make HTTP calls but it contains several complicated steps.&lt;/p&gt;

&lt;p&gt;Let’s see a simple CURL request in PHP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$url = “https://api.cloudways.com/api/v1”
$resource = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, [â€˜Accept:application/json, Content-Type:application/json’]);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, â€˜GET’);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You need to call the curl_setopt() method to define the header and the particular HTTP verb like GET, POST, PUT, etc. It does look pretty complicated. So, what is a better and robust alternative?&lt;/p&gt;

&lt;p&gt;Here comes &lt;a href="http://docs.guzzlephp.org/" rel="noopener noreferrer"&gt;Guzzle&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let’s see how Guzzle creates a request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$client = new GuzzleHttp\Client();
$res = $client-&amp;gt;request(â€˜GET’, â€˜https://api.cloudways.com/api/v1’, [
â€˜headers’ =&amp;gt; [
â€˜Accept’ =&amp;gt; â€˜application/json’,
â€˜Content-type’ =&amp;gt; â€˜application/json’
]])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You could see that it is simple. You just need to initialize the Guzzle client and give HTTP verbs and a URL. After that, pass the array of headers and other options.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understand the Guzzle Client
&lt;/h2&gt;

&lt;p&gt;Guzzle is a simple PHP HTTP client that provide an easy method of creating calls and integration with web services. It is the standard abstraction layer used by the API to send messages over the server. Several prominent features of Guzzle are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Guzzle can send both synchronous and asynchronous requests.&lt;/li&gt;
&lt;li&gt;It provides a simple interface for building query strings, POST requests, -&lt;/li&gt;
&lt;li&gt;streaming large uploads &amp;amp; downloads, uploading JSON data, etc.&lt;/li&gt;
&lt;li&gt;Allows the use of other PSR7 compatible libraries with Guzzle.&lt;/li&gt;
&lt;li&gt;Allows you to write environment and transport agnostic code.&lt;/li&gt;
&lt;li&gt;Middleware system allows you to augment and compose client behavior.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Install Guzzle In PHP
&lt;/h2&gt;

&lt;p&gt;The preferred way of installing Guzzle is Composer. If you haven’t installed Composer yet, download it from here&lt;br&gt;
Now to install Guzzle, run the following command in SSH terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;composer require guzzlehttp/guzzle&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command will install the latest version of Guzzle in your PHP project. Alternatively you can also define it as a dependency in the composer.json file and add the following code in it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
 “require”: {
 “guzzlehttp/guzzle”: “~6.0”
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, run the composer install command. Finally you need to require the autoloader and added some more files to use Guzzle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require â€˜vendor/autoload.php’;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Request;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The installation process is over and now it’s time to work with a real example of creating HTTP calls with an API. For the purpose of this article, I will work with &lt;a href="https://developers.cloudways.com/" rel="noopener noreferrer"&gt;Cloudways API&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What You Can Do With the Cloudways API
&lt;/h2&gt;

&lt;p&gt;Cloudways is a managed hosting provider for PHP, Magento, WordPress and many other frameworks and CMS. It has an API that you could use for performing CRUD operations on servers and applications. Check out popular &lt;a href="https://www.cloudways.com/blog/category/use-cases/api/" rel="noopener noreferrer"&gt;use cases of the Cloudways API&lt;/a&gt; to see how you could integrate it into your projects.&lt;/p&gt;

&lt;p&gt;In this article, I am going to create HTTP calls to perform specific operations with Guzzle on Cloudways server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create the HTTP Requests In Guzzle
&lt;/h2&gt;

&lt;p&gt;As I mentioned earlier, creating HTTP requests in Guzzle is very easy; you only need to pass the base URI, HTTP verb and headers. If there is an authentication layer in the external API, you can also pass these parameters in Guzzle. Similarly, Cloudways API needs email and API key to authenticate users and send the response. You need to &lt;a href="https://platform.cloudways.com/" rel="noopener noreferrer"&gt;sign up&lt;/a&gt; for a Cloudways account to get your API credentials.&lt;/p&gt;

&lt;p&gt;Let’s start by creating a CloudwaysAPIClient.php file to set up Guzzle for making HTTP calls. I will also create a class and several methods using HTTP calls in them.&lt;/p&gt;

&lt;p&gt;The URL of the API does not change so I will use const datatype for it. Later on, I will concatenate it with other URL suffixes to get the response. Additionally, I have declared variables $auth_key,$auth_email which will hold the authentication email and the API key. $accessToken will hold the temporary token which will be renewed every time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Class CloudwaysAPIClient
{
private $client = null;
const API_URL = “https://api.cloudways.com/api/v1";
var $auth_key;
var $auth_email;
var $accessToken;
public function __construct($email,$key)
{
$this-&amp;gt;auth_email = $email;
$this-&amp;gt;auth_key = $key;
$this-&amp;gt;client = new Client();
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create a Post Request to get Access Token
&lt;/h2&gt;

&lt;p&gt;The access token will be generated from this URL: &lt;strong&gt;&lt;a href="https://api.cloudways.com/api/v1/oauth/access_token" rel="noopener noreferrer"&gt;https://api.cloudways.com/api/v1/oauth/access_token&lt;/a&gt;&lt;/strong&gt; every time I access the API. This will be set in $url with additional data array which holds auth credentials. Later on, I created a POST request with the base URL and query string. The response will be decoded and access token is saved to be used within the methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function prepare_access_token()
{
try
{
$url = self::API_URL . “/oauth/access_token”;
$data = [â€˜email’ =&amp;gt; $this-&amp;gt;auth_email,’api_key’ =&amp;gt; $this-&amp;gt;auth_key];
$response = $this-&amp;gt;client-&amp;gt;post($url, [â€˜query’ =&amp;gt; $data]);
$result = json_decode($response-&amp;gt;getBody()-&amp;gt;getContents());
$this-&amp;gt;accessToken = $result-&amp;gt;access_token;
}
catch (RequestException $e)
{
$response = $this-&amp;gt;StatusCodeHandling($e);
return $response;
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the POST request for getting access token is completed. Additionally, If you observed in the exception handling, I declared a method StatusCodeHandling($e), which will take care of the response codes (HTTP codes like 404, 401, 200 etc), and throw a related exception.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function StatusCodeHandling($e)
{
if ($e-&amp;gt;getResponse()-&amp;gt;getStatusCode() == â€˜400’)
{
$this-&amp;gt;prepare_access_token();
}
elseif ($e-&amp;gt;getResponse()-&amp;gt;getStatusCode() == â€˜422’)
{
$response = json_decode($e-&amp;gt;getResponse()-&amp;gt;getBody(true)-&amp;gt;getContents());
return $response;
}
elseif ($e-&amp;gt;getResponse()-&amp;gt;getStatusCode() == â€˜500’)
{
$response = json_decode($e-&amp;gt;getResponse()-&amp;gt;getBody(true)-&amp;gt;getContents());
return $response;
}
elseif ($e-&amp;gt;getResponse()-&amp;gt;getStatusCode() == â€˜401’)
{
$response = json_decode($e-&amp;gt;getResponse()-&amp;gt;getBody(true)-&amp;gt;getContents());
return $response;
}
elseif ($e-&amp;gt;getResponse()-&amp;gt;getStatusCode() == â€˜403’)
{
$response = json_decode($e-&amp;gt;getResponse()-&amp;gt;getBody(true)-&amp;gt;getContents());
return $response;
}
else
{
$response = json_decode($e-&amp;gt;getResponse()-&amp;gt;getBody(true)-&amp;gt;getContents());
return $response;
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The main client class is now completed. I will extend it to create more HTTP requests for different cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a GET Request to Fetch All Servers
&lt;/h2&gt;

&lt;p&gt;Once the User is authenticated, I can fetch all my servers and applications from Cloudways. /server is the suffix concatenated with the base URI. This time, I will attach the accessToken with Authorization string in Guzzle header to fetch all servers in JSON response. To do this, create a new method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Public function get_servers()
{
try
{
$url = self::API_URL . “/server”;
$option = array(â€˜exceptions’ =&amp;gt; false);
$header = array(â€˜Authorization’=&amp;gt;’Bearer â€˜ . $this-&amp;gt;accessToken);
$response = $this-&amp;gt;client-&amp;gt;get($url, array(â€˜headers’ =&amp;gt; $header));
$result = $response-&amp;gt;getBody()-&amp;gt;getContents();
return $result;
}
catch (RequestException $e)
{
$response = $this-&amp;gt;StatusCodeHandling($e);
return $response;
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now create &lt;strong&gt;index.php&lt;/strong&gt; file and include &lt;strong&gt;CloudwaysAPIClient.php&lt;/strong&gt; at the top. Next, I will declare my API key and email, passing it to the class constructor to finally get the servers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;include â€˜CloudwaysAPIClient.php’;
$api_key = â€˜W9bqKxxxxxxxxxxxxxxxxxxxjEfY0’;
$email = â€˜shahroze.nawaz@cloudways.com’;
$cw_api = new CloudwaysAPIClient($email,$api_key);
$servers = $cw_api-&amp;gt;get_servers();
echo â€˜&amp;lt;pre&amp;gt;’;
var_dump($servers);
echo â€˜&amp;lt;/pre&amp;gt;’;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s test it in Postman to verify that the information and right response codes are being fetched.&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%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2A67IO8OPa2CqVN_XOBdff8Q.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%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2A67IO8OPa2CqVN_XOBdff8Q.png" alt="1*67IO8OPa2CqVN_XOBdff8Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So all my servers hosted on the Cloudways Platforms are being fetched. Similarly, you can create new methods with HTTP calls to get applications, server settings, services and etc.&lt;/p&gt;

&lt;p&gt;Let’s create a PUT call to change the label of the server which is cloned-php applications at the moment. But first, I need to get the server ID &amp;amp; label because this information will be used as an argument. To get the server ID, create a foreach loop in the index.php file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;foreach($servers-&amp;gt;servers as $server){
echo $server-&amp;gt;id;
echo $server-&amp;gt;label;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if I hit the API, it will fetch the server id and label.&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%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2A-lpI1dadZj_Q51Hs2Y2NrA.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%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2A-lpI1dadZj_Q51Hs2Y2NrA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a PUT Request to Change Server Label
&lt;/h2&gt;

&lt;p&gt;Now to change the server label, I need to create a PUT call in Guzzle. I will extend the class with a new method. Remember that server id and label are two necessary parameters that will be passed in the method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function changelabel($serverid,$label)
{
try
{
$url = self::API_URL . “/server/$serverid”;
$data = [â€˜server_id’ =&amp;gt; $serverid,’label’ =&amp;gt; $label];
$header = array(â€˜Authorization’=&amp;gt;’Bearer â€˜ . $this-&amp;gt;accessToken);
$response = $this-&amp;gt;client-&amp;gt;put($url, array(â€˜query’ =&amp;gt; $data,’headers’ =&amp;gt; $header));
return json_decode($response-&amp;gt;getBody()-&amp;gt;getContents());
}
catch (RequestException $e)
{
$response = $this-&amp;gt;StatusCodeHandling($e);
return $response;
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now in the &lt;strong&gt;index.php&lt;/strong&gt;, put this condition beneath the &lt;strong&gt;foreach&lt;/strong&gt; loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if($server-&amp;gt;id == â€˜71265’ &amp;amp;&amp;amp; $server-&amp;gt;label == â€˜Cloned-php applications’){
$label = â€˜Cloudways Server’;
$changelabel = $cw_api-&amp;gt;changelabel($server-&amp;gt;id,$label);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When testing this in Postman, I will get the updated server label.&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%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2A3ZDP0TnRK57UEb1SW2oETA.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%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2A3ZDP0TnRK57UEb1SW2oETA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a Delete Request to Remove a Server
&lt;/h2&gt;

&lt;p&gt;To delete a server using Cloudways API, I need to create a &lt;strong&gt;Delete&lt;/strong&gt; request in Guzzle through the following method. This is pretty similar to the above method, because it also requires two parameters, server id and label.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function deleteServer($serverid,$label)
{
try
{
$url = self::API_URL . “/server/$serverid”;
$data = [â€˜server_id’ =&amp;gt; $serverid,’label’ =&amp;gt; $label];
$header = array(â€˜Authorization’=&amp;gt;’Bearer â€˜ . $this-&amp;gt;accessToken);
$response = $this-&amp;gt;client-&amp;gt;delete($url, array(â€˜query’ =&amp;gt; $data,’headers’ =&amp;gt; $header));
return json_decode($response-&amp;gt;getBody()-&amp;gt;getContents());
}
catch (RequestException $e)
{
$response = $this-&amp;gt;StatusCodeHandling($e);
return $response;
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try this in Postman or just refresh the page. The server will be deleted.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Words
&lt;/h2&gt;

&lt;p&gt;Guzzle is a flexible HTTP client that you could extend as per your requirements. You can also try out new ideas with uploading data, form fields, cookies, redirects and exceptions. You can also create middleware for authentication layer (if needed). All in all, Guzzle is a great option for creating REST API in PHP, without using any frameworks.&lt;/p&gt;

&lt;p&gt;If you have any questions or query you can comment below.&lt;/p&gt;

</description>
      <category>restapi</category>
      <category>guzzle</category>
      <category>php</category>
    </item>
    <item>
      <title>Creating RESTful API Using Slim Micro-Framework </title>
      <dc:creator>Cloudways</dc:creator>
      <pubDate>Thu, 23 Mar 2017 11:51:51 +0000</pubDate>
      <link>https://forem.com/cloudways/creating-restful-api-using-slim-micro-framework</link>
      <guid>https://forem.com/cloudways/creating-restful-api-using-slim-micro-framework</guid>
      <description>&lt;p&gt;&lt;em&gt;This article was originally published at Cloudways: &lt;a href="https://www.cloudways.com/blog/simple-rest-api-with-slim-micro-framework/" rel="noopener noreferrer"&gt;Creating A Simple REST API With Slim Framework&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The internet is chock full of third-party and custom APIs that offer a wide range of functionalities. PHP offers several frameworks for web app development rapidly. However, time is always the enemy of web developers and the app needs to be pushed at an impossible deadline. In such times, frameworks are the best option for rapid application development.&lt;/p&gt;

&lt;p&gt;In this tutorial, I will introduce you to Slim framework for PHP. Slim is fast becoming the most-opted framework for API development and small web apps. Although you can create REST API in several other frameworks like CakePHP, Symfony Laravel, Codeigniter, they have a steep learning curve and are often too cumbersome to use in rapid development scenarios.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Slim Framework
&lt;/h2&gt;

&lt;p&gt;Slim is super lightweight framework, ideal for rapid web app development. One of the important usages is in REST API development. Slim supports all HTTP method (GET,POST,PUT,DELETE). Slim contains very handy URL structure with routers, middlewares, bodyparser along with page templates, flash messages, encrypted cookies and lots more.&lt;/p&gt;

&lt;p&gt;At this point, it is important to understand the structure of the REST API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding REST API
&lt;/h2&gt;

&lt;p&gt;REST is the abbreviation of Representational State Transfer. This is a bridge or medium between data resource and application interface, whether it's on mobile devices or desktops. REST provides a block of HTTP methods which are used to alter the data. The following are common HTTP methods:&lt;/p&gt;

&lt;p&gt;GET is used for reading and retrieving data.&lt;br&gt;
POST    is used for inserting data.&lt;br&gt;
PUT is used for updating data.&lt;br&gt;
DELETE  is used for deleting data.&lt;/p&gt;

&lt;p&gt;Basically, REST phenomena works on actions and resources. Whenever any action URL is invoked, it performs an individual method (or a set of methods) on that URL. I will further discuss this below with examples.&lt;/p&gt;

&lt;p&gt;First we will need to install Slim framework for the REST API project.&lt;/p&gt;

&lt;p&gt;I assume that you already have your &lt;a href="https://platform.cloudways.com/signup" rel="noopener noreferrer"&gt;Cloudways server launched with PHPstack&lt;/a&gt; and if you didn't launch your server signup to get 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%2Ft2679wqkgkp4885ang9c.gif" 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%2Ft2679wqkgkp4885ang9c.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After creating the server  launch SSH terminal.&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%2F465m0opazg2yzbflpy8b.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%2F465m0opazg2yzbflpy8b.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: Install Slim Framework From Composer
&lt;/h2&gt;

&lt;p&gt;Open SSH terminal from the Cloudways panel and and sign in with your username and password. Now go to the folder where you want to install SLIM with cd command&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%2F15p721rs0u1uh7eb2ele.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%2F15p721rs0u1uh7eb2ele.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Input the following command in the terminal to install Slim via composer.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;composer require slim/slim"^3.0"&lt;/code&gt;&lt;br&gt;
&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%2F9v65ud3edg5kdyohlpse.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%2F9v65ud3edg5kdyohlpse.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After installing Slim, the following piece of code will require it in the index.php file to require autoload file and instantiate Slim.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

require 'vendor/autoload.php';
$app = new Slim\App();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Composer comes pre-installed on Cloudways servers. If you are working on the localhost, you need to install it. If you haven't installed it yet, just go to the following link and follow the instructions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Making a .htaccess File for Clean URL Structure
&lt;/h2&gt;

&lt;p&gt;To make your life easier, you should create a .htaccess file that defines clean URL structure. At the root directory, make a .htaccess file and add the below code in it. This will provide a clean URL structure for the PHP file. (this just means that you don't want to include PHP filename in the URL calls).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RewriteEngine On

RewriteCond %{Request_Filename} !-F

RewriteCond %{Request_Filename} !-d

RewriteRule ^ index.php [QSA,L]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If your index file is located in different folder (for instance, the “public” folder),  then you can insert the full path of the index file in the last line:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;RewriteRule ^ public/index.php [QSA,L]&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Create a Database in MySQL
&lt;/h2&gt;

&lt;p&gt;With each PHP Stack on Cloudways, you get an empty database.&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%2Ftqxn80yidu8t8q9kqkzo.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%2Ftqxn80yidu8t8q9kqkzo.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on Launch Database Manager. To create the requisite tables, run the following query in SQL Command box:&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%2Fv2es0zhc43dtqcxywqct.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%2Fv2es0zhc43dtqcxywqct.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE IF NOT EXISTS `library` (

Â `book_id` int(11) NOT NULL,

Â `book_name` varchar(100) NOT NULL,

Â `book_isbn` varchar(100) NOT NULL,

Â `book_category` varchar(100) NOT NULL

) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

INSERT INTO `library` (`book_id`, `book_name`, `book_isbn`, `book_category`) VALUES

(1, 'PHP', 'bk001', 'Server Side'),

(3, 'javascript', 'bk002', 'Client Side'),

(4, 'Python', 'bk003', 'Data Analysis');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now it is time for the first API call. Let's make it systematically.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Retrieving All Books
&lt;/h2&gt;

&lt;p&gt;Enter the following code in the index.php file to get all the books from the database. A GET call is used for retrieval.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$app-&amp;gt;get('/books', function() {

Â require_once('db.php');

Â $query = "select * from library order by book_id";

Â $result = $connection-&amp;gt;query($query);

Â // var_dump($result);

Â while ($row = $result-&amp;gt;fetch_assoc()){

$data[] = $row;

Â }

Â echo json_encode($data);

});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To streamline working with the API calls, I recommend using &lt;a href="https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en" rel="noopener noreferrer"&gt;Postman&lt;/a&gt; (available from the Chrome App Store). This plugin greatly helps in API management and usage.&lt;/p&gt;

&lt;p&gt;In postman, make a GET call with API URL.&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%2Fwx9ymiqugt28pkyt98or.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%2Fwx9ymiqugt28pkyt98or.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Creating a Book's Record
&lt;/h2&gt;

&lt;p&gt;Make a new API call in the index.php  through the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$app-&amp;gt;post('/books', function($request){

Â require_once('db.php');

Â $query = "INSERT INTO library (book_name,book_isbn,book_category) VALUES (?,?,?)";

Â $stmt = $connection-&amp;gt;prepare($query);

Â $stmt-&amp;gt;bind_param("sss",$book_name,$book_isbn,$book_category);

Â $book_name = $request-&amp;gt;getParsedBody()['book_name'];

Â $book_isbn = $request-&amp;gt;getParsedBody()['book_isbn'];

Â $book_category = $request-&amp;gt;getParsedBody()['book_category'];

Â Â $stmt-&amp;gt;execute();

});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open Postman and click Body. Select x.www-form-urlencoded. Now add records to insert via POST call.&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%2Fiyil5v8eye4sv6ql8pze.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%2Fiyil5v8eye4sv6ql8pze.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Updating a Book's Record
&lt;/h2&gt;

&lt;p&gt;Make a new API call like below to update a record in the database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$app-&amp;gt;put('/books/{book_id}', function($request){

Â require_once('db.php');

Â $get_id = $request-&amp;gt;getAttribute('book_id');

Â $query = "UPDATE library SET book_name = ?, book_isbn = ?, book_category = ? WHERE book_id = $get_id";

Â $stmt = $connection-&amp;gt;prepare($query);

Â $stmt-&amp;gt;bind_param("sss",$book_name,$book_isbn,$book_category);

Â $book_name = $request-&amp;gt;getParsedBody()['book_name'];

Â $book_isbn = $request-&amp;gt;getParsedBody()['book_isbn'];

Â $book_category = $request-&amp;gt;getParsedBody()['book_category'];

Â $stmt-&amp;gt;execute();

});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Postman, add data to update a specific book record.&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%2Fsbutdq802u7z0qzspih7.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%2Fsbutdq802u7z0qzspih7.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Deleting a Book's Record
&lt;/h2&gt;

&lt;p&gt;To delete a record with a specific ID, a DELETE call is required.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$app-&amp;gt;delete('/books/{book_id}', function($request){

Â require_once('db.php');

Â $get_id = $request-&amp;gt;getAttribute('book_id');

Â $query = "DELETE from library WHERE book_id = $get_id";

Â $result = $connection-&amp;gt;query($query);

});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On Postman, run the call like this&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%2Fqvnmcjh1yybyhtn31y23.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%2Fqvnmcjh1yybyhtn31y23.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is all for the basic REST API in the Slim Framework. However, this API will not work until you add this command at the end of the code.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$app-&amp;gt;run();&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;Creating and using the REST API with Slim framework is very easy. The biggest advantage of the framework is its ease of use and lightweight. The icing on the cake is that it is very easy to learn and a good developer could pick up the framework in a matter of hour. To summarize, Slim receives HTTP requests, review them and invokes the appropriate callback routine for HTTP requests and return the appropriate response(s).&lt;/p&gt;

&lt;p&gt;If you need clarification about this article or have any other query about the Slim Framework, do let me know through the comment section.&lt;/p&gt;

</description>
      <category>slim</category>
      <category>phpmicroframework</category>
      <category>php</category>
      <category>restapi</category>
    </item>
    <item>
      <title>How PHP Will Fare In 2017?</title>
      <dc:creator>Cloudways</dc:creator>
      <pubDate>Wed, 04 Jan 2017 13:57:26 +0000</pubDate>
      <link>https://forem.com/cloudways/how-php-will-fare-in-2017</link>
      <guid>https://forem.com/cloudways/how-php-will-fare-in-2017</guid>
      <description>

&lt;p&gt;For the PHP community, the best news in 2016 was the release of version 7.1. While many initially saw PHP 7.1 as a minor release with bug fixes, it proved to be a whole different beast altogether. The version offered important improvements, a new return type (void) and Multi Catch Exception Handling.&lt;/p&gt;

&lt;p&gt;This year, I went to the PHP community and asked about the general feelings and expectations about the trends that would dominate the PHP world in 2017. Essentially, I asked three questions in the Reddit thread:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What was the best thing that happened to PHP in 2016?&lt;/li&gt;
&lt;li&gt;What does the community thinks of PHP 7 and 7.1?&lt;/li&gt;
&lt;li&gt;What is the best PHP framework?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In addition, I asked about the community's response on the issue of official termination of support for PHP 5.6.&lt;/p&gt;

&lt;p&gt;In addition to the Reddit, I also posed these questions via email to several community influencers. I received the following responses:&lt;/p&gt;

&lt;p&gt;Cal Evans, Technical Manager at Zend Technologies and godfather of the PHP community responded:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Versions 7 and 7.1 of PHP are not the revolutionary changes that we got in the later 5.x versions. They are however proof that PHP has stabilized, matured, and has a predictable path forward.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In response to the question about the frameworks, Evans was very clear.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Frameworks exist only to make developers lives better. Some developers won't want to sweat the details, they want to just get things done. There is nothing wrong with this and frameworks like Laravel will always exist to fill this need. In our ecosystem, Laravel stands above all others with the tooling and ecosystem built around it to help developers just get things done.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Alex Makarov, a major contributor to Yii offered a personal insight for the question about PHP version 7+.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;While 7.0 was excellent revolutionary release, there was design issue with return types and returning null preventing me from using it. 7.1 added nullable types and now I'm happy.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When talking about favorite PHP framework, Makarov added:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Depends on what is the definition of “the best”. If we're talking about “most popular in US then it should be Laravel. If it's “most popular in ex-USSR and asia then it's Yii. If we're talking about enterprise level support, that's Symfony without any doubt. If it's about features and performance, Yii has more out of the box.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Stefan Koopmanschap, cofounder of PHPBenelux loved PHP 7+.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I love it. I think it is a great step in the development of the language, PHP is a seriously mature language now, which can easily compete with other languages. And it's being used for highly scalable and business-critical applications.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;His response on the question of favorite framework echoed the sentiments of “framework-independent developers.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There is no best framework. There is a best fit for every use case. Symfony, Laravel, Zend Framework, Yii, Expressive, Silex, Slim, the list is endless, and each of the frameworks has a place. Which framework fits your use case depends on the requirements of the application, the developers you have on your team, the infrastructure it will be running on, and a lot of other factors.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I would like to start discussing the Reddit poll with the comment by the Reddit user leeharris100, that sums up the PHP trends for 2017 very succinctly:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is why I think PHP will continue to be popular for a long time to come. It's easy to make applications of any size and scope. There is documentation and support for every single problem you could ever think of. And it's finally hit the point where performance is mostly acceptable.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I ran a &lt;a href="https://www.reddit.com/r/webdev/comments/5gsrwp/what_do_you_think_about_php_trends_in_2017/"&gt;poll on Reddit&lt;/a&gt; and got some excellent answers from PHP experts, all over the world. I will now offer a summary of the answers to all four questions, so that the readers could form their own opinions.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Was the Best Thing That Happened to PHP in 2016?
&lt;/h2&gt;

&lt;p&gt;The majority of respondents agreed that speed was one area where PHP greatly improved in 2016. In the concise words of a Reddit commentator:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;PHP is fast as h*ll!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The improvements in speed is the main benefit of PHP 7 (introduced near the end of 2015).&lt;/p&gt;

&lt;p&gt;For some users, the best thing about 2016 was the increased maturity of PHP libraries and frameworks. I think Reddit user ajr901 put it best in the comment:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Speed, ease of development (sort of?), ease of deployment, arguably better frameworks and tooling available for PHP.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I believe that both these developments (the increase in speed and the maturity of libraries) are the direct result of the introduction of PHP 7 and 7.1. This brings me to the next question&lt;/p&gt;

&lt;h2&gt;
  
  
  What Does the Community Thinks About PHP 7 and 7.1?
&lt;/h2&gt;

&lt;p&gt;The community loves the new PHP 7. The improvements in almost all areas of the language come together in a very fast package that removes one of the major complaints about PHP.&lt;/p&gt;

&lt;p&gt;In the words of Reddit user hedsht:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;it's a major step into the right direction, type hinting will hopefully silence some haters.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The community agrees that PHP 7+ is the best thing that has happened to the language so far. Almost every respondent on Reddit and Facebook agreed that PHP has entered a whole new era with the introduction of PHP 7. PHP 7.1 sweetened the pot even further by introducing speed related improvements that have impacted every framework and library.&lt;/p&gt;

&lt;p&gt;Many respondents felt that PHP is now ready for enterprise level projects because of the speed of PHP 7. A Reddit commentator the_goose_says wrote:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The most important thing about PHP in 2016 is speed. PHP has always been used by millions, but the largest companies have avoided it because speed matters so much at that level. With PHP 7+, we may have more household names using PHP.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What Is the Best PHP Framework?
&lt;/h2&gt;

&lt;p&gt;The real meat of the discussion (and this is true for every PHP related discussion!) was about the framework preferred by the users. Everyone has their own favorite framework that they use in their projects. In response to the question about the best PHP framework, everyone opted for their own favorite.&lt;/p&gt;

&lt;p&gt;I asked the community to select their favorite from Symfony, Yii2 and Laravel. Interestingly, some Reddit commentators also brought in Codeigniter and their own custom PHP frameworks into the debate.&lt;/p&gt;

&lt;p&gt;Overwhelmly, the comments favored Laravel among the three, with Symfony coming in the second place. I think diabetesjones summed up the debate:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Laravel is the smoothest coding I've ever had. Yii is fight-the-system every step of the way.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Finally, on the question of the termination of support for PHP 5.6, the community was not very divided. Several commentators said that if PHP 5.6 projects have been implemented using the best practices, there is nothing to worry about. In the words of scootstah, a Reddit commentator:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Anything that is 5.6 compliant will be able to migrate to 7 with little to no difficulty. You're only going to have problems if you were already 5 years behind the times.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What Will the (Probable) PHP Trends for 2017?
&lt;/h2&gt;

&lt;p&gt;I see three major trends that would dominate the PHP world in the year 2017.&lt;/p&gt;

&lt;p&gt;The first and the most probable trend is the complete dominance of PHP 7.x in all aspects of PHP development. In part this will be an outcome of the discontinued support for PHP5.6. However, the most important aspect of this trend is the fact that PHP 7.x introduced several important improvements to the language and PHP development for websites and web apps.&lt;/p&gt;

&lt;p&gt;The second important and related PHP trend in 2017 would be the release of major versions of all important frameworks. Right now, the bulk of all major frameworks (Symfony, Laravel and Yii) is built on older versions of PHP. In 2017, the released versions would embrace PHP 7 completely and would make available the important  features as part of the tooling and scaffolding of the frameworks.&lt;/p&gt;

&lt;p&gt;Finally, major (and minor) web hosting providers of all flavors would upgrade to PHP 7.x. While this is a no-brainer, given the popularity of PHP7.x, anyone who has ever used a web  host knows how difficult it is to get the web hosting company to upgrade anything! I think, 2017 would the year when PHP 7.x would be available as the default PHP version everywhere.&lt;/p&gt;

&lt;p&gt;In conclusion, the PHP community is very optimistic about PHP 7+ and all the possibilities the new versions offer for projects of all descriptions and scale. When it comes to frameworks, Laravel and Laravel based CMS have captured the attention of the community for the moment and there is little indication that other frameworks would come up with a game changer!&lt;/p&gt;

&lt;p&gt;If you think PHP would go in a different direction or would like to extend the discussion, please leave a comment below!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://www.cloudways.com/blog/php-trends-2017/"&gt;www.cloudways.com&lt;/a&gt; on December 27, 2016&lt;/em&gt;&lt;/p&gt;


</description>
      <category>php2017</category>
      <category>phptrends</category>
      <category>php</category>
    </item>
  </channel>
</rss>
